# Terminal
`deft/stdext/terminal` is a thin session wrapper over the native `term/*`
PTY namespace plus a `Terminal` protocol for components that own a
session and want lifecycle hooks.
import "deft/stdext/terminal" as term
## API
| Def / Type | Signature | Description |
|---|---|---|
| `spawn-default` | `{| opts |}` | Spawn a PTY with defaults merged under `opts` |
| `Terminal` (protocol) | `session {}` / `on-exit {| code |}` | Contract for components owning a session |
`spawn-default` fills `%{ cols 80 rows 24 term "xterm-256color" }` and
calls `term/spawn`. The rest of the namespace (`term/write`,
`term/paste`, `term/resize`, `term/scroll`, `term/snapshot-version`,
`term/title`, `term/exited?`, `term/dispose`, `term/draw`,
`term/forward-event`) is host stdlib, available in the TUI hosts
(retro / retra / hydra) — not in the standalone `deft` binary.
## Example
import "deft/stdext/terminal" as term def t [term/spawn %{ cmd "/bin/sh" cols 100 rows 30 }] [term/write $t "echo hello\r"] set v [term/snapshot-version $t] [term/dispose $t]
defimpl MyApp Terminal { session {} { return $self~term } on-exit {| code | echo "exited" $code } }
The protocol is a contract for components that embed a terminal; the
shipped terminal panel (`packages/term`) implements `Panel` directly
with its own `Terminal` type, so treat the protocol as an extension
point rather than something the built-in app uses.
## See Also
- TUI Overview — hosts and panels
- Widgets and Protocols — defining protocols
- Graphics — `draw/*` used to paint snapshots