// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! Drive an interactive program from Zig, in the manner of Tcl's `expect`: //! start it, wait for one of several regular expressions to turn up in what it //! prints, learn which one did and what it captured, and send it input in //! reply. //! //! ```zig //! const Prompt = enum { login, password, shell }; //! //! var buffer: [4096]u8 = undefined; //! var session = try expect.Session.spawn(io, gpa, &buffer, .{ //! .argv = &.{ "ssh", "host" }, //! .environ_map = init.environ_map, //! }); //! defer session.deinit(); //! //! var result = try session.expect(Prompt, &.{ //! .{ .tag = .password, .regex = &password_re }, //! .{ .tag = .shell, .regex = &shell_re }, //! }, expect.within(.fromSeconds(10))); //! defer result.deinit(gpa); //! switch (result.tag) { ... } //! ``` //! //! Regular expressions are zregex's, compiled by the caller, so one compiled //! pattern can be reused across calls and sessions. const std = @import("std"); pub const zregex = @import("zregex"); pub const Session = @import("Session.zig"); pub const Pattern = Session.Pattern; pub const Result = Session.Result; pub const Options = Session.Options; pub const Transport = Session.Transport; pub const Winsize = Session.Winsize; pub const SpawnError = Session.SpawnError; pub const ExpectError = Session.ExpectError; pub const SendError = Session.SendError; /// A timeout for `Session.expect` that runs out `duration` from now, on the /// clock that does not count time the machine spends suspended. pub fn within(duration: std.Io.Duration) std.Io.Timeout { return .{ .duration = .{ .raw = duration, .clock = .awake } }; } test { // The tests drive `/bin/sh`, which Windows does not have. if (@import("builtin").os.tag != .windows) _ = @import("tests.zig"); }