83a75672
build: wire ghostty-vt module
a73x 2026-04-08 05:57
Commit message
build.zig
| Old | New | ||
|---|---|---|---|
| @@ -4,11 +4,27 @@ pub fn build(b: *std.Build) void { | |||
| 4 | const target = b.standardTargetOptions(.{}); | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | const optimize = b.standardOptimizeOption(.{}); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | // Lazy-fetch the ghostty dependency. On the first invocation this | ||
| 8 | // materializes the package; subsequent builds use the local cache. | ||
| 9 | const ghostty_dep = b.lazyDependency("ghostty", .{}); | ||
| 10 | |||
| 11 | // vt module — wraps ghostty-vt | ||
| 12 | const vt_mod = b.createModule(.{ | ||
| 13 | .root_source_file = b.path("src/vt.zig"), | ||
| 14 | .target = target, | ||
| 15 | .optimize = optimize, | ||
| 16 | }); | ||
| 17 | if (ghostty_dep) |dep| { | ||
| 18 | vt_mod.addImport("ghostty-vt", dep.module("ghostty-vt")); | ||
| 19 | } | ||
| 20 | |||
| 21 | // Main executable module | ||
| 7 | const exe_mod = b.createModule(.{ | 22 | const exe_mod = b.createModule(.{ |
| 8 | .root_source_file = b.path("src/main.zig"), | 23 | .root_source_file = b.path("src/main.zig"), |
| 9 | .target = target, | 24 | .target = target, |
| 10 | .optimize = optimize, | 25 | .optimize = optimize, |
| 11 | }); | 26 | }); |
| 27 | exe_mod.addImport("vt", vt_mod); | ||
| 12 | 28 | ||
| 13 | const exe = b.addExecutable(.{ | 29 | const exe = b.addExecutable(.{ |
| 14 | .name = "waystty", | 30 | .name = "waystty", |
| @@ -25,13 +41,30 @@ pub fn build(b: *std.Build) void { | |||
| 25 | run_step.dependOn(&run_cmd.step); | 41 | run_step.dependOn(&run_cmd.step); |
| 26 | 42 | ||
| 27 | const test_step = b.step("test", "Run unit tests"); | 43 | const test_step = b.step("test", "Run unit tests"); |
| 28 | const test_mod = b.createModule(.{ | 44 | |
| 45 | // Test main.zig (and transitively vt.zig via its import) | ||
| 46 | const main_test_mod = b.createModule(.{ | ||
| 29 | .root_source_file = b.path("src/main.zig"), | 47 | .root_source_file = b.path("src/main.zig"), |
| 30 | .target = target, | 48 | .target = target, |
| 31 | .optimize = optimize, | 49 | .optimize = optimize, |
| 32 | }); | 50 | }); |
| 33 | const tests = b.addTest(.{ | 51 | main_test_mod.addImport("vt", vt_mod); |
| 34 | .root_module = test_mod, | 52 | const main_tests = b.addTest(.{ |
| 53 | .root_module = main_test_mod, | ||
| 54 | }); | ||
| 55 | test_step.dependOn(&b.addRunArtifact(main_tests).step); | ||
| 56 | |||
| 57 | // Test vt.zig directly (runs the ghostty-vt smoke test) | ||
| 58 | const vt_test_mod = b.createModule(.{ | ||
| 59 | .root_source_file = b.path("src/vt.zig"), | ||
| 60 | .target = target, | ||
| 61 | .optimize = optimize, | ||
| 62 | }); | ||
| 63 | if (ghostty_dep) |dep| { | ||
| 64 | vt_test_mod.addImport("ghostty-vt", dep.module("ghostty-vt")); | ||
| 65 | } | ||
| 66 | const vt_tests = b.addTest(.{ | ||
| 67 | .root_module = vt_test_mod, | ||
| 35 | }); | 68 | }); |
| 36 | test_step.dependOn(&b.addRunArtifact(tests).step); | 69 | test_step.dependOn(&b.addRunArtifact(vt_tests).step); |
| 37 | } | 70 | } |
src/main.zig
| Old | New | ||
|---|---|---|---|
| @@ -1,5 +1,7 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const vt = @import("vt"); | ||
| 2 | 3 | ||
| 3 | pub fn main() !void { | 4 | pub fn main() !void { |
| 4 | std.debug.print("waystty\n", .{}); | 5 | std.debug.print("waystty\n", .{}); |
| 6 | _ = vt; | ||
| 5 | } | 7 | } |
src/vt.zig
| Old | New | ||
|---|---|---|---|
| @@ -0,0 +1,56 @@ | |||
| 1 | //! Thin wrapper around the ghostty-vt Zig module. | ||
| 2 | //! | ||
| 3 | //! ## ghostty-vt API notes (as of ghostty-1.3.2-dev) | ||
| 4 | //! | ||
| 5 | //! ### Terminal lifecycle | ||
| 6 | //! var t: Terminal = try .init(alloc, .{ .cols = N, .rows = N }); | ||
| 7 | //! defer t.deinit(alloc); | ||
| 8 | //! try t.printString("raw text"); // writes plain text | ||
| 9 | //! try t.resize(alloc, new_cols, new_rows); | ||
| 10 | //! const s = try t.plainString(alloc); // heap copy of visible text | ||
| 11 | //! defer alloc.free(s); | ||
| 12 | //! | ||
| 13 | //! ### VT stream processing | ||
| 14 | //! TerminalStream wraps a Terminal and processes raw VT byte sequences. | ||
| 15 | //! Stream is the lower-level parser/dispatcher. | ||
| 16 | //! | ||
| 17 | //! ### RenderState (stateful renderer helper) | ||
| 18 | //! var state: RenderState = .empty; | ||
| 19 | //! defer state.deinit(alloc); | ||
| 20 | //! try state.update(alloc, &terminal); | ||
| 21 | //! // state.rows (CellCountInt), state.cols, state.colors, state.cursor | ||
| 22 | //! // state.row_data: std.MultiArrayList(RenderState.Row) | ||
| 23 | //! // state.dirty: RenderState.Dirty — caller should clear after use | ||
| 24 | //! | ||
| 25 | //! ### Input encoding | ||
| 26 | //! ghostty_vt.input.encodeKey(buf, key_event, opts) -> encode a KeyEvent | ||
| 27 | //! ghostty_vt.input.encodeMouse(buf, event, opts) -> encode a mouse event | ||
| 28 | //! ghostty_vt.input.encodeFocus(buf, event) -> encode focus in/out | ||
| 29 | //! ghostty_vt.input.encodePaste(buf, data, opts) -> bracketed-paste wrap | ||
| 30 | //! | ||
| 31 | //! ### Key types | ||
| 32 | //! input.Key, input.KeyAction, input.KeyEvent, input.KeyMods | ||
| 33 | //! input.KeyEncodeOptions | ||
| 34 | //! | ||
| 35 | //! ### Mouse types | ||
| 36 | //! input.MouseAction, input.MouseButton, input.MouseEncodeOptions, | ||
| 37 | //! input.MouseEncodeEvent | ||
| 38 | //! | ||
| 39 | //! ### Namespaces re-exported at top level | ||
| 40 | //! apc, dcs, osc, point, color, device_status, formatter, highlight, | ||
| 41 | //! kitty, modes, page, parse_table, search, sgr, size, x11_color, sys | ||
| 42 | //! | ||
| 43 | //! ### Sizes | ||
| 44 | //! size.CellCountInt — integer type for column/row counts | ||
| 45 | //! | ||
| 46 | //! ### Cursor | ||
| 47 | //! Screen.Cursor / Cursor — position and style within a Screen | ||
| 48 | //! CursorStyle, CursorStyleReq | ||
| 49 | |||
| 50 | const std = @import("std"); | ||
| 51 | const ghostty_vt = @import("ghostty-vt"); | ||
| 52 | |||
| 53 | test "ghostty-vt module imports" { | ||
| 54 | // Smoke test — just reference the module so the import is verified | ||
| 55 | _ = ghostty_vt; | ||
| 56 | } | ||