Async line-read, and the decoder and text handling in Bjolang

- read-event, line-read and the editor loop work in both colours. The
  leaf is read-bytes, a defbjouble: a bjoroutine awaits the glue's read,
  other code blocks. with-raw-mode takes a body of either colour.
- Cancelling the scope of a waiting line-read ends it and restores the
  terminal modes. The glue runs reads one at a time.
- The key decoder is (bjoterm keys), and widths, prompt escapes, search
  and common prefixes are (bjoterm text). Clusters and categories come
  from (std unicode grapheme) and (std unicode chars).
- Keys.cs and Text.cs are removed. The glue is termios, signals, poll
  and read.
- New tests: tests/async.bjo and tests/text.bjo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-11-30 21:05:59 +01:00
parent 6863503fa7
commit ce778f9b1e
11 changed files with 970 additions and 733 deletions

View file

@ -30,7 +30,7 @@ is in raw mode, and gives it back as it found it.
- The keys are those of Emacs and readline, listed at ~line-read~. Up and
Down move between the lines of the input, and reach the history only
on its first and last line.
- The buffer is a vector of grapheme clusters (glue/Text.cs). Widths
- The buffer is a vector of grapheme clusters ((std unicode grapheme)). Widths
follow ~wcwidth~ with a table of wide ranges; a C0 control shows as
~^X~, a tab as spaces to the next multiple of 8.
- The editor breaks lines itself: a line break where the next cluster does
@ -39,8 +39,26 @@ is in raw mode, and gives it back as it found it.
- Each key is a pure step from one state to the next (~line-step~), so
~simulate-line~ tests the keys without a terminal.
- History files have one entry per line, with "\n" and "\\" escaped.
- Not done: an async ~line-read~ for a fiber (it is ~#:sync~), and
redrawing after a terminal reflows lines when it narrows.
- Not done: redrawing after a terminal reflows lines when it narrows.
*Async, and less C# (2026-11-30).*
- ~read-event~ and everything above it work in both colours. The one leaf
is ~read-bytes~, a ~defbjouble~: in a bjoroutine it awaits the glue's
read, elsewhere it parks the thread on a fiber of the caller's scope.
The compiler makes the suspending copies of ~read-event~, ~line-read~
and the editor loop. ~with-raw-mode~ takes a body of either colour
(~-?->~), and ~line-read~ passes it a bjoroutine in its suspending copy.
- Cancelling the scope around a waiting ~line-read~ ends it, and the
modes come back.
- Moved to Bjolang: the decoder (~(bjoterm keys)~), the wait for the rest
of a sequence, the widths and prompt escapes (~(bjoterm text)~), search
and common prefixes. Clusters and the Unicode categories come from
~(std unicode grapheme)~ and ~(std unicode chars)~; only the East Asian
wide ranges are a table of our own. The glue is termios, the signals,
and ~poll~ and ~read~ of bytes.
- Reads of the glue run one at a time: a read waits for the one before
it, which ends soon after it is cancelled.
- Decision 11 (a C# decoder) is replaced by this.
* Decisions