esc

A terminal

An add-on can run a program on a pseudo-terminal, usually the person's shell, and Ledge draws its screen in the notch: vim, top and ssh work. The add-on runs the program; Ledge sends what's typed and the size, and never starts a program itself. Needs LedgeKit 0.18.0.

A whole terminal

Add "terminal" to both surfaces and capabilities in addon.json, and set kit.minAPI to 0.18.0. The person approves an add-on that runs programs as them before it starts; a manifest with the surface and not the capability is refused. AddOnTerminal does the rest:

let terminal = AddOnTerminal()
var handlers = AddOnHandlers()
terminal.connect(&handlers)        // the person's login shell, started on Ledge's first size
exit(await AddOnSession.run(id: "terminal", handlers: handlers))

connect starts the login shell at the size Ledge sends when the page first shows, starts it again on the next key after it ends, tells Ledge the folder after each Return, and hangs it up when the add-on is turned off. Pass start: to run something else, or somewhere other than home. ledgekit new --terminal writes this for you.

What goes back and forth

DirectionWhatIn LedgeKit
Ledge → add-onWhat the person typed or pasted, in orderonTerminalInput
Ledge → add-onThe size in characters, first when the page showsonTerminalResize
Add-on → LedgeWhat the program wrote, in order, in 32 KB piecesAddOnSession.terminal(output:)
Add-on → LedgeThe folder, and whether the program still runsshow(terminal:)

Output and typing each keep their order end to end. Ledge shows the folder's end in the notch and opens it in the person's terminal app from its button.

What's typed is theirs

Write what arrives in onTerminalInput to the program and nowhere else: never log it, store it or send it. ledgekit lint warns about a file that handles it and also logs or stores something. Programs in the terminal can copy to the clipboard, but Ledge never answers one asking to read it.

Checking it without Ledge

ledgekit check gives the terminal 80 × 24, and script steps type into it; the report's terminal.output is the screen as text:

[{"wait": 1.5}, {"type": "echo hello; cd /tmp\n"}, {"wait": 1}]