bjoterm: raw mode, key events and escape sequences
- (bjoterm terminal): terminal-open, with-raw-mode, terminal-size,
terminal-suspend, read-event and read-event/timeout, and escape
sequences for the cursor, clearing, the alternate screen, bracketed
paste and styles. Linux only.
- glue/Tty.cs: termios, poll on fd 0, SIGWINCH, SIGCONT, SIGTSTP, and
restoring the modes at SIGTERM, SIGHUP, SIGQUIT and process exit.
- glue/Keys.cs: the decoder of CSI and SS3 keys with modifiers, Alt,
UTF-8 and bracketed paste.
- Tests: the decoder from bytes, and raw mode on a pseudo-terminal under
script. plan.org has the decisions and the phases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:31:29 +01:00
|
|
|
|
## Comment Style
|
|
|
|
|
|
|
|
|
|
|
|
Write plain, direct engineering comments. Do **not** imitate the overly literary
|
|
|
|
|
|
or cryptic comment style found in some older files in this repo.
|
|
|
|
|
|
|
|
|
|
|
|
- **Use standard terms:** "returns" (not "answers"), "rejects/errors" (not "refuses"),
|
|
|
|
|
|
"resolves/looks up" (not "names/spells"), "traverses" (not "walks").
|
|
|
|
|
|
- **Name concepts directly:** Say "trait constraints" instead of "what the code around it asks".
|
|
|
|
|
|
- **Use normal sentences with verbs:** Start docstrings with a verb ("Checks whether...",
|
|
|
|
|
|
"Returns...", "Resolves...") rather than cryptic noun fragments.
|
|
|
|
|
|
- **Keep it short:** 1–2 sentences for most functions. Only add more to explain a
|
|
|
|
|
|
non-obvious invariant or edge case. Skip comments that just restate the code.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
- Bad: `/// Several answers as one: refused if any refuses, held if all hold, and otherwise not known yet.`
|
|
|
|
|
|
- Good: `/// Combines tri-state results: Some false if any failed, Some true if all passed, else None.`
|
|
|
|
|
|
|
|
|
|
|
|
- Bad: `/// What a file is called, worked out from where it is.`
|
|
|
|
|
|
- Good: `/// Module identity derived from a file's path on disk.`
|
|
|
|
|
|
|
|
|
|
|
|
## This package
|
|
|
|
|
|
|
|
|
|
|
|
- `bjo build` builds the library and the glue in `glue/`.
|
2026-11-30 21:05:59 +01:00
|
|
|
|
- Keep logic in Bjolang. The glue is for what Bjolang cannot call: termios,
|
|
|
|
|
|
signals and `poll`/`read`. For Unicode, use `(std unicode ...)`.
|
|
|
|
|
|
- Modules: `(bjoterm keys)` decodes input, `(bjoterm text)` measures text,
|
|
|
|
|
|
`(bjoterm terminal)` reads events and has the escape sequences,
|
|
|
|
|
|
`(bjoterm line)` is the line editor.
|
2026-11-30 20:49:26 +01:00
|
|
|
|
- `bjo test` runs the tests:
|
|
|
|
|
|
- `tests/keys.bjo`: the decoder, from bytes.
|
|
|
|
|
|
- `tests/line.bjo`: the line editor's keys, history and completion,
|
|
|
|
|
|
through `simulate-line`, without a terminal.
|
|
|
|
|
|
- `tests/terminal.bjo` and `tests/line-terminal.bjo`: raw mode and
|
|
|
|
|
|
`line-read` on a pseudo-terminal, under `script`.
|
2026-11-30 21:05:59 +01:00
|
|
|
|
- `tests/text.bjo`: clusters and widths.
|
2026-11-30 21:24:16 +01:00
|
|
|
|
- `tests/reflow.bjo`: the redraw after the terminal narrows, with and
|
|
|
|
|
|
without reflow, under `script`.
|
2026-11-30 21:05:59 +01:00
|
|
|
|
- `tests/async.bjo`: `line-read` in a bjoroutine, and cancelled by a
|
|
|
|
|
|
deadline.
|
2026-11-30 20:49:26 +01:00
|
|
|
|
- `examples/keys.bjo` prints events; `examples/repl.bjo` is a small REPL.
|
bjoterm: raw mode, key events and escape sequences
- (bjoterm terminal): terminal-open, with-raw-mode, terminal-size,
terminal-suspend, read-event and read-event/timeout, and escape
sequences for the cursor, clearing, the alternate screen, bracketed
paste and styles. Linux only.
- glue/Tty.cs: termios, poll on fd 0, SIGWINCH, SIGCONT, SIGTSTP, and
restoring the modes at SIGTERM, SIGHUP, SIGQUIT and process exit.
- glue/Keys.cs: the decoder of CSI and SS3 keys with modifiers, Alt,
UTF-8 and bracketed paste.
- Tests: the decoder from bytes, and raw mode on a pseudo-terminal under
script. plan.org has the decisions and the phases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:31:29 +01:00
|
|
|
|
- `plan.org` has the decisions and the phases.
|