Condukt.Sandbox.Terminal (Condukt v3.0.0)

Copy Markdown View Source

A shell in a sandbox that people type into, shared while an agent works.

The shell is a sandbox process (Condukt.Sandbox.start_process/4) with stdin and a pseudo-terminal, run through util-linux script, so it needs Condukt.Sandbox.write_process/4. The terminal process follows its output and sends each subscriber {Condukt.Sandbox.Terminal, id, {:output, chunk}}, and {Condukt.Sandbox.Terminal, id, {:exit, status}} once the shell ends. Input is written at the offset the terminal tracks, so a write repeated after a lost reply lands once.

{:ok, term} = Condukt.Sandbox.Terminal.start_link(sandbox, id: "pairing")
:ok = Condukt.Sandbox.Terminal.subscribe(term)
:ok = Condukt.Sandbox.Terminal.write(term, "make test\r")

A subscriber that joins late gets the last 64 KiB from subscribe/1's reply first. The shell's size is the pseudo-terminal's default, 80x24: resizing needs a PTY the sandbox's node controls, which none offers yet. Stopping the terminal kills the shell.

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a shell. Options: :id (the sandbox process id, default a new one), :shell (default bash -il), :cwd, and :env.

Stops the terminal and kills its shell.

Subscribes the caller and returns the scrollback so far.

Writes input, as typed: a newline is \r.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(sandbox, opts \\ [])

Starts a shell. Options: :id (the sandbox process id, default a new one), :shell (default bash -il), :cwd, and :env.

stop(terminal)

Stops the terminal and kills its shell.

subscribe(terminal)

Subscribes the caller and returns the scrollback so far.

write(terminal, data)

Writes input, as typed: a newline is \r.