diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 07:42:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | ed185f305731309cbddb981166678a552f2fda84 (patch) | |
| tree | 1eb984c60c25ba131d0a8a99e5fbbc2131fcc4aa /examples/live/test/live.script | |
| parent | c009f708e631700fb1d65ccba2c8229c10054528 (diff) | |
| download | sketchbook-ed185f305731309cbddb981166678a552f2fda84.tar.gz sketchbook-ed185f305731309cbddb981166678a552f2fda84.zip | |
examples/live: pardes's editor in State, typed with helix's keys
The plain buffer of part 1 gives way to pardes's text pane as a library
(`pardes-editor`, src/lib_editor.zig there): `Editor(.{ .text = 4096,
.undo = 16 KiB, .registers = 1024, .selections = 64 })`, a value of plain
data, 39,264 bytes of a State of 43,480. The package takes pardes by path
(`../../../02-pardes-code`, the checkout beside sketchbook's) with
`.editor = true` and its smallest tree-sitter set; sketchbook is spelled
`../../../sketchbook` as pardes spells it, since a package is told by its
path's spelling and sketchbook's build.zig cannot be two modules.
`update` turns events into keys: printables from `text` events only,
specials (Escape, Return, Backspace, Tab, arrows, Home, End, pages,
Delete) and ctrl or alt chords (helix's `A-I` an upper-case letter) from
`key_down`, a chord's letter dropped if it also comes as text. Each call
into the editor thaws the value into a static 128 KiB buffer reset for
the call (`update` may not allocate from the host; a key at 4 KiB of text
took 29 KiB of it). The text is compiled when the editor's `revision`
moves.
Measured (a scratch bench through `update`, the survey's program, 646
bytes, a key typed into its middle, 400 times): a typed key, edit and
compile, 59.5 us best and 78.8 mean in Debug, 7.4 and 7.8 in
ReleaseFast; a motion 6.4 and 0.3. The package's cold `zig build lib`
went from 3.1 s to 6.6 s, its first build under `--watch -fincremental`
from 4.0 to 5.9 s, and an edit of main.zig rebuilt under it from
0.062-0.067 s to 0.067-0.092 s.
Test: test/live.script types through helix now (`i`, the text, Escape,
`gl`, `h`, `rx` for the edit, `l` `d` to break the line, `u` to mend it)
and still replays to equal text, tapes and screenshots, its seeks moved
to the marks' new times. zig build test: 81 of 81 steps, 6 of 6 tests.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'examples/live/test/live.script')
| -rw-r--r-- | examples/live/test/live.script | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/examples/live/test/live.script b/examples/live/test/live.script index 695d16a..ecf3d77 100644 --- a/examples/live/test/live.script +++ b/examples/live/test/live.script @@ -1,9 +1,12 @@ -# A program typed, its tapes after each line, a broken line and its mend; -# then this run's session played back, and sought to two moments marked as -# they happened. (A mark ends a clip, `record`, so the session is replayed.) +# A program typed through the editor (helix's keys: `i`, text, Escape, +# motions), its tapes after each line, a broken line and its mend (an +# undo); then this run's session played back, and sought to two moments +# marked as they happened. (A mark ends a clip, `record`, so the session is +# replayed.) # Screenshots land in .zig-cache/live/ for review; they are compared over # the picture alone (640,300 600x300: not the text, the scope or the time). frames 2 +type i type out = sin(tau * 220 * t) * 0.3 expect problem.len 0 expect out.len 8 @@ -17,45 +20,51 @@ type color = hsv(x, 0.5, y) expect color.len 4 expect color.code[0].op x expect color.code[3].op hsv +key escape +expect ed.cursor.mode normal frames 2 console save typed screenshot .zig-cache/live/gradient.png -# An edit: y becomes x, and the picture changes. -key backspace -key backspace -type x) +# An edit: y becomes x (to the line's end, a character left, replaced), +# and the picture changes. +type gl +type h +type rx expect color.len 3 expect color.code[2].op hsv expect color.code[2].c 0 frames 2 screenshot .zig-cache/live/edited.png expect-different-screenshot .zig-cache/live/gradient.png .zig-cache/live/edited.png 640 300 600 300 -# Broken: the tape and the picture stay, the problem is set at its byte. -key backspace +# Broken: the ) deleted; the tape and the picture stay, the problem is set +# at its byte. +type l +type d expect problem.at 52 expect color.len 3 expect color.code[2].c 0 frames 2 screenshot .zig-cache/live/broken.png expect-same-screenshot .zig-cache/live/edited.png .zig-cache/live/broken.png 0 640 300 600 300 -# Mended. -type ) +# Mended: undone. +type u expect problem.len 0 expect color.len 3 console save end # Played back from the start, then sought: each moment's text, tapes and # time as they were live, leaf by leaf (a mark is taken before its frame's -# tick: 0.2667 s and 0.4833 s; a seek lands on the last frame at or before). +# tick: 0.3 s and 0.5333 s; a seek lands on the last frame at or before). console play session 0 frames 100 -console seek 488 +console seek 538 expect-snapshot end -console seek 272 +console seek 305 expect-snapshot typed expect color.len 4 screenshot .zig-cache/live/sought.png expect-same-screenshot .zig-cache/live/gradient.png .zig-cache/live/sought.png 0 0 0 1000 600 # Live again from there: the typed program, before its edit. console stop -expect len 53 +expect ed.front 53 +expect ed.back 0 expect color.code[3].op hsv |
