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/build.zig | |
| 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/build.zig')
| -rw-r--r-- | examples/live/build.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/examples/live/build.zig b/examples/live/build.zig index 9d0983d..ccfd32d 100644 --- a/examples/live/build.zig +++ b/examples/live/build.zig @@ -30,7 +30,16 @@ pub fn build(b: *std.Build) void { .{ .name = "scope", .module = sb.modules.scope }, }; - const app = sb.app(.{ .name = "live", .root_source_file = b.path("src/main.zig"), .imports = imports }); + // The editor: helix's keys over a value kept in State. Its tree-sitter + // set is the smallest there is (Zig's grammar), as the language's own + // grammar is handed in at run time. + const pardes = b.dependency("pardes", .{ .target = target, .optimize = optimize, .@"tree-sitter" = .zig, .editor = true }); + const app = sb.app(.{ .name = "live", .root_source_file = b.path("src/main.zig"), .imports = &.{ + .{ .name = "Lang", .module = lang }, + .{ .name = "shaders", .module = shaders.module }, + .{ .name = "scope", .module = sb.modules.scope }, + .{ .name = "pardes-editor", .module = pardes.module("pardes-editor") }, + } }); const steps = app.addSteps(.{ .scripts = &.{b.path("test/live.script")} }); const lang_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/Lang.zig"), .target = target, .optimize = optimize }) }); steps.test_step.dependOn(&b.addRunArtifact(lang_test).step); |
