Cross-platform PTY (pseudo-terminal) spawning for MoonBit native targets, integrated with moonbitlang/async.
let exit_code = @pty.with_pty(
"sh", [],
rows=24, cols=80,
cwd="/workspace",
) <| pty => {
let pid : Int = pty.pid()
pty.resize(rows=40, cols=120)
pty.write(b"ls\nexit\n") // Pty implements @io.Writer
let text = pty.read_all().text() // ... and @io.Reader
pty.wait()
}@async.with_task_group() <| session => {
let pty = @pty.spawn(session, "sh", [])
session.spawn_bg(no_wait=true, () => forward_input(pty))
while pty.read_some() is Some(chunk) {
handle(chunk)
}
}type PtyInstall
Download zipCross-platform PTY (pseudo-terminal) spawning for MoonBit native targets, integrated with moonbitlang/async.