diff options
Diffstat (limited to 'src/Core.zig')
| -rw-r--r-- | src/Core.zig | 176 |
1 files changed, 115 insertions, 61 deletions
diff --git a/src/Core.zig b/src/Core.zig index c5187616..ecfd8fa7 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -39,6 +39,7 @@ const Rect = pardes.Rect; const Registers = pardes.Registers; const RowMetrics = pardes.RowMetrics; const Store = @import("Store.zig"); +const Plumb = @import("Plumb.zig"); const Db = pardes.Db; const Stream = pardes.Stream; const Surface = pardes.Surface; @@ -72,7 +73,6 @@ const memory = pardes.memory; const modal = pardes.modal; const mouse = pardes.mouse; const newer_build_words = pardes.newer_build_words; -const pager = pardes.pager; const platform = pardes.platform; const recent_files = @import("recent.zig"); const sel_slot = pardes.sel_slot; @@ -208,9 +208,9 @@ db: Db = .{}, /// (`stdio.h`, `<foo.h>`) is tried in, in order. The session's, seeded /// with C's (/usr/include, /usr/local/include), kept in a dump. incl: std.ArrayList([]u8) = .empty, -/// Plumb's rules, the user's, tried in order before the built-in ones -/// (look.resolve), the first to match taking the look. Kept in a dump. -plumb: std.ArrayList([]u8) = .empty, +/// The plumber's rules (Plumb.zig): plumb/rules and plumb/send's, the +/// defaults (`include basic`) until something writes others. Kept in a dump. +plumber: Plumb = .{}, /// Zerox's groups of panes on one buffer (File.syncTwins), and the id /// the next takes. twin_groups: std.ArrayList(pardes.panes.File.TwinGroup) = .empty, @@ -227,6 +227,11 @@ next_serial: u32 = 0, /// The column whose tag the running command came from, while it runs: /// the column acme's commands take from their Text's col. exec_column: ?usize = null, +/// While a word a plumbing rule started runs (Plumb.run): whether it +/// declined the message, saying nothing (Diff on a file with no hunk, a +/// revision outside a git work tree), so that the send is refused and a +/// look looks itself. Null while no rule's word runs. +plumb_declined: ?bool = null, /// Panes made this step that found no room in their column /// (layout.placeNew): closed at the step's end, once whatever made them /// is done with them. @@ -246,7 +251,7 @@ session_dir_len: ?u16 = null, settings: config.Runtime = .{ .font = .{ .tagline_percent = config.gui_tagline_font_percent } }, locations_config: locations.Config = .{}, locations_cache: locations.Cache = .{}, -tty_filter_palette: pardes.panes.terminal.FilterPalette = .{}, +tty_filter_palette: pardes.Term.FilterPalette = .{}, font_request_taken: bool = false, custom_theme: ?Theme = null, /// bodyChrome's: the theme it was worked out for, and it. @@ -267,8 +272,10 @@ unattended: bool = false, haptic: HapticSlot = if (platform == .macos) .none else {}, /// The look just run found nothing (look.zig missed). look_missed: bool = false, -/// The look being run opens a .diff or .patch as text, not its +Diff: -/// Diff going back from a +Diff, Edit's B (it edits the file). +/// The look being run opens what it names, unplumbed (Plumb.zig): a +/// .diff as text, not stacked in a +Diff (Diff going back from a +Diff, +/// Edit's B, which edits the file), and the `edit` port's open of a +/// message the plumber already matched. look_text: bool = false, look_hover_wait: ?look.LookHoverWait = null, /// The place a look-hover last found nothing to open: the pointer @@ -362,10 +369,10 @@ restore_req: ?[]const u8 = null, restore_buf: [1024]u8 = @splat(0), surface: Surface = .{}, -/// A replica's predicted echo (src/echo.zig), drawn over its terminals: +/// A replica's predicted echo (src/term/echo.zig), drawn over its terminals: /// presentation, its own, in no digest and no rollback copy. Null on a /// session's own core. -echo: ?*pardes.echo.Echo = null, +echo: ?*pardes.Echo = null, /// The live view, `views[live]` (`view()`): whose input the session /// takes now, and whose share of the panes is in their own fields /// (views.zig). `views_open` says which views there are, one a window @@ -389,11 +396,11 @@ scratch: std.heap.ArenaAllocator, /// that still own their loop pass their own arena to `render` instead. frame_arena: std.heap.ArenaAllocator, /// the terminal motion surface, memoized against the pane it was built -/// for — see panes.terminal.RowsCache for the lifetime rule -shell_rows: pardes.panes.terminal.RowsCache = .{}, +/// for — see edit.RowsCache for the lifetime rule +shell_rows: pardes.edit.RowsCache = .{}, /// Finished command panes' output, and whether it is a diff -/// (File.DiffOutput). -diff_output: pardes.panes.File.DiffOutput = .{}, +/// (ansi.DiffOutput). +diff_output: pardes.ansi.DiffOutput = .{}, /// What the replay digest leaves out (src/walk.zig): what drawing /// keeps, what is recomputed, and what only the session that performs @@ -519,7 +526,17 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { p.boot = Boot.of(opts); // Asked once, at the start, whoever asks first after. _ = p.sessionDir(); - switch (p.boot) { + // A core built without a terminal (a test configuration: core-test's) + // boots to a scratch pane where a shell would have been, and says why + // once. + const shell_boot = switch (p.boot) { + .tty, .tty_shell, .shell, .classic => true, + .document, .missing, .stdin => false, + }; + if (pardes.Term.ops == null and shell_boot) { + _ = try pardes.panes.newScratch(p, 0, 0, .scratch); + p.oneColumn(); + } else switch (p.boot) { .document => { const path = opts.file.?; const opened = initial_doc: { @@ -566,7 +583,7 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { p.oneColumn(); }, .stdin => { - const page = try pager.parse(gpa, opts.stdin_text.?); + const page = try pardes.Term.page(gpa, opts.stdin_text.?); errdefer gpa.free(page.spans); const content = page.text; errdefer gpa.free(content); @@ -757,8 +774,7 @@ pub fn deinit(p: *Pardes) void { p.recent.deinit(p.recentGpa()); for (p.incl.items) |dir| p.gpa.free(dir); p.incl.deinit(p.gpa); - for (p.plumb.items) |rule| p.gpa.free(rule); - p.plumb.deinit(p.gpa); + p.plumber.deinit(p.gpa); for (p.twin_groups.items) |group| p.gpa.free(group.path); p.twin_groups.deinit(p.gpa); p.fs.batch.bytes.deinit(p.gpa); @@ -862,9 +878,9 @@ fn reportFocus(p: *Pardes) void { }; if (std.meta.eql(want, v.focus_told)) return; if (v.focus_told) |old| if (p.panes[old.id]) |pane| { - if (pane.serial == old.serial and pardes.panes.terminal.reportsFocus(pane)) p.emitWrite(old.id, "\x1b[O"); + if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O"); }; - if (want) |new| if (pardes.panes.terminal.reportsFocus(p.panes[new.id].?)) p.emitWrite(new.id, "\x1b[I"); + if (want) |new| if (pardes.Term.modes(p.panes[new.id].?.terminal).focus) p.emitWrite(new.id, "\x1b[I"); v.focus_told = want; } @@ -993,7 +1009,16 @@ pub fn acknowledgeShell(p: *Pardes, id: usize, executable: []const u8, prompt_ma } else |_| {} } }; - if (id < MAX_PANES) pardes.panes.terminal.shellSpawned(p, id, prompt_marks); + // The lines queued for it go when it can take them: at its first + // prompt, or now when it draws no marks to wait for. + if (id < MAX_PANES) if (p.panes[id]) |pane| if (pane.isTerminal() and pane.pending_command.wait == .spawn) { + if (prompt_marks) { + pane.pending_command.wait = .input; + } else { + pane.greet = false; + pane.releasePendingCommand(p, id, true); + } + }; if (p.settings.shell.effective.set(executable)) p.settings.shell.pending = false; } @@ -1599,7 +1624,7 @@ pub fn update(p: *Pardes, ev: Event) void { const pane = p.panes[o.pane] orelse return; pane.shell_spoke = true; ctlfs.events.notePtyOutput(p, o.pane, o.bytes); - pardes.panes.terminal.feedOutput(p, pane, o.bytes); + pane.feedOutput(p, o.bytes); ctlfs.pty.noteMarks(p, o.pane, pane); exec.flushReplEnter(p, o.pane, true); }, @@ -1796,10 +1821,7 @@ pub fn sync(p: *Pardes) void { // What the terminal answers its program (a cursor report, its // attributes) goes as typed bytes go: behind whatever is still // queued for its pty, never ahead of it nor dropped. - if (pane.terminal) |state| { - p.emitWrite(id, state.reply[0..state.reply_len]); - state.reply_len = 0; - } + if (pane.terminal) |state| p.emitWrite(id, pardes.Term.replies(state)); const r = v.rects[id]; // The session's part of the pane's view geometry (File.geometry), // and its context declarations. @@ -1864,7 +1886,7 @@ pub fn sync(p: *Pardes) void { // doc panes have no pty/emulator grid to reflow; just record // the size so bodyText renders the right number of rows if (pane.isTerminal()) { - pardes.panes.terminal.resizeGrid(pane, cols, rows); + pane.resizeGrid(cols, rows); p.shell_rows.markStale(pane); // reflow moved every row p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = cols, .rows = rows } }); pane.fs.winsize = null; @@ -1873,19 +1895,23 @@ pub fn sync(p: *Pardes) void { pane.rows = rows; if (pane.file) |*file| file.syntax_dirty = true; } - pane.pan = pardes.panes.terminal.panFor(p, pane, r); + pane.pan = pane.panFor(p, r); // A directory pane's entries follow its width, as acme's // columns do (Dir.fit). if (pane.file) |file| if (file.listing != null and r.h > pane.tag_rows) pardes.panes.Dir.fit(p, pane, pane.cols); - pardes.panes.terminal.releasePendingCommandIfReady(p, id, pane); + if (pane.pending_command.wait == .input) pane.releasePendingCommand(p, id, tape.value(.prompt, struct { + fn ready(at: *const Pane) bool { + return pardes.Term.prompt(at.terminal).input_ready; + } + }.ready, .{pane})); // Which bands a pane shows is the step's, as its geometry is: // what is drawn under them, and where a click lands, read it. Messages.collectNotices(p, pane, r, id); // The greeting `ls` of a new terminal in a directory is typed at // its shell's FIRST prompt, or never: typed later it would land // in whatever runs then, or in the middle of a line someone - // typed (panes.terminal.greeting). - if (pane.greet and pane.isTerminal() and p.resize_count > 0) switch (tape.value(.prompt, pardes.panes.terminal.greeting, .{pane})) { + // typed (Pane.greeting). + if (pane.greet and pane.isTerminal() and p.resize_count > 0) switch (tape.value(.prompt, Pane.greeting, .{pane})) { .wait => {}, .never => pane.greet = false, .now => { @@ -1909,7 +1935,7 @@ fn typedInto(p: *Pardes) void { /// Whether the live view sizes terminal `pane`: a terminal shown at two /// sizes takes the size of the view that typed into it last, and any /// view's once that one is gone. The others show it at that size, a -/// shorter one passed down to its cursor (`Pane.pan`, terminal.panFor). +/// shorter one passed down to its cursor (`Pane.pan`, Pane.panFor). // ponytail: a panned view's pointer reports to a terminal's program and // its kitty images are placed as the unpanned rows are. fn sizes(p: *Pardes, pane: *Pane) bool { @@ -1988,7 +2014,7 @@ pub fn nextWake(p: *const Pardes) ?u64 { // A terminal's kitty animation, at its next frame. Only a time still // ahead counts: a pane not drawn keeps the last one it was given, // and a past one would wake every frame for nothing. - for (p.panes) |slot| if (slot) |pane| if (pardes.panes.terminal.animationDueMs(pane)) |due_ms| { + for (p.panes) |slot| if (slot) |pane| if (pane.terminal) |state| if (pardes.Term.due(state)) |due_ms| { const due = due_ms *| std.time.ns_per_ms; if (due > p.clock.stepped_ns) { const wait = @max(1, (due - p.clock.stepped_ns + frame_ns - 1) / frame_ns); @@ -2159,7 +2185,7 @@ pub const Options = struct { file: ?[]const u8 = null, file_line: usize = 0, missing: ?struct { word: []const u8, dir: []const u8 } = null, - /// `pardes -`: stdin as it came, for a +Pager pane at boot (pager.zig + /// `pardes -`: stdin as it came, for a +Pager pane at boot (Term.page /// parses it). stdin_text: ?[]const u8 = null, tty_toggle: u21 = config.tty_toggle_default, @@ -2293,6 +2319,7 @@ test "topbar hover highlights exactly the executable word" { } test "pane-tag Exec prefers Term and argument builtins before shell fallback" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30 }); defer p.deinit(); @@ -2468,6 +2495,7 @@ test "TreeContext command and custom tag survive a workspace round trip" { test "Filter is ordered after Del and toggles only its terminal or +Pager pane" { const testing = std.testing; + if (pardes.Term.ops == null) return error.SkipZigTest; // it reads the emulator const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin; const filter = std.meta.stringToEnum(Builtin, "Filter") orelse return error.MissingFilterBuiltin; try testing.expectEqual(@backingInt(del) + 1, @backingInt(filter)); @@ -2476,12 +2504,12 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane" defer p.deinit(); while (p.nextEffect()) |_| {} const first = p.panes[0].?; - const palette_before = first.terminal.?.vt.colorForXterm(.{ .palette = 1 }).?; + const palette_before = pardes.Term.emulatorOf(first.terminal.?).vt.colorForXterm(.{ .palette = 1 }).?; try testing.expect(first.tty_filter); try testing.expect(p.executeBuiltinLine(0, "Filter")); try testing.expect(!first.tty_filter); - try testing.expect(palette_before.eql(first.terminal.?.vt.colorForXterm(.{ .palette = 1 }).?)); + try testing.expect(palette_before.eql(pardes.Term.emulatorOf(first.terminal.?).vt.colorForXterm(.{ .palette = 1 }).?)); const second_id = p.freeSlot().?; const second = try p.newShell(second_id, ""); @@ -2514,6 +2542,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane" } test "compact tag commands stay beside their own prefix across layout changes" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30 }); defer p.deinit(); @@ -2558,6 +2587,7 @@ test "compact tag commands stay beside their own prefix across layout changes" { } test "Term spawns a raw shell in the caller's directory" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); @@ -2583,6 +2613,7 @@ test "Term spawns a raw shell in the caller's directory" { } test "a terminal respawned into a closed pane's slot hangs the old shell up first" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell // Hosts keep a shell per slot: were the spawn first, the close would // end the new shell and leave the old one running. const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -2653,6 +2684,7 @@ test "an empty column shows its theme's empty_col under its tag: acme's white, e } test "unknown Exec from a document runs as a command pane in its directory, typed into no terminal" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); defer p.deinit(); @@ -2680,6 +2712,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type } test "Exec in a terminal whose tty is taken runs as a command pane instead of typing at the program" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); defer p.deinit(); @@ -2711,6 +2744,7 @@ test "Exec in a terminal whose tty is taken runs as a command pane instead of ty } test "a command of several lines keeps its tag one row, and its echo does not staircase" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); @@ -2731,12 +2765,13 @@ test "a command of several lines keeps its tag one row, and its echo does not st _ = exec.execute(p, 1, two); while (p.nextEffect()) |_| {} _ = try p.render(frame.allocator()); - const body = try pardes.panes.terminal.screenTextAlloc(pane, gpa); + const body = try pardes.Term.scrollback(pane.terminal, gpa); defer gpa.free(body); try std.testing.expect(std.mem.indexOf(u8, body, "% def greet(name):\n return name") != null); } test "a spawn is for the pane it was made for, not whatever took the slot since" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); @@ -2767,6 +2802,7 @@ test "a spawn is for the pane it was made for, not whatever took the slot since" } test "a REPL bound for a language takes the exec made on a body in it; tags, Exec by name and command words still run" { + if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .shells = 3, .cols = 100, .rows = 30 }); defer p.deinit(); @@ -3007,6 +3043,7 @@ test "a restored terminal's tag names neither the REPL it was nor the shell it h } test "a Term started by a shell's path keeps the path in its Term+ word" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); while (p.nextEffect()) |_| {} @@ -3017,6 +3054,7 @@ test "a Term started by a shell's path keeps the path in its Term+ word" { } test "Tty, Term's old name in saved tags, runs as Term, bare and with its +shell" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); while (p.nextEffect()) |_| {} @@ -3029,6 +3067,7 @@ test "Tty, Term's old name in saved tags, runs as Term, bare and with its +shell } test "Term+fish, one word a tag can hold, opens a terminal on that shell" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); while (p.nextEffect()) |_| {} @@ -3058,6 +3097,7 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" { } test "a command pane shows how its command ended, and the next command there runs below it" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); defer p.deinit(); @@ -3070,7 +3110,7 @@ test "a command pane shows how its command ended, and the next command there run const pane = p.panes[dst].?; // Its first command is echoed as every later one is. { - const first = try pardes.panes.terminal.screenTextAlloc(pane, gpa); + const first = try pardes.Term.scrollback(pane.terminal, gpa); defer gpa.free(first); try std.testing.expect(std.mem.startsWith(u8, first, "% make -j8")); } @@ -3101,16 +3141,16 @@ test "a command pane shows how its command ended, and the next command there run // A program that crashed out of its full screen leaves the emulator // in its modes; the next command starts clear of them. p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } }); - try std.testing.expect(pardes.panes.terminal.bracketedPaste(pane)); + try std.testing.expect(pardes.Term.modes(pane.terminal).bracketed_paste); // Done, the directory's next command runs there, below what it showed. try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "make test")); - try std.testing.expect(!pardes.panes.terminal.bracketedPaste(pane)); + try std.testing.expect(!pardes.Term.modes(pane.terminal).bracketed_paste); var respawned = false; while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane == dst) { respawned = true; }; try std.testing.expect(respawned); - const body = try pardes.panes.terminal.screenTextAlloc(pane, gpa); + const body = try pardes.Term.scrollback(pane.terminal, gpa); defer gpa.free(body); const said = std.mem.indexOf(u8, body, "compiled") orelse return error.OutputLost; const ended = std.mem.indexOf(u8, body, "exit 2") orelse return error.ExitLost; @@ -3156,6 +3196,7 @@ test "a command pane shows how its command ended, and the next command there run } test "a terminal its program gave back takes command lines again" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{}); defer p.deinit(); @@ -3189,6 +3230,7 @@ test "a terminal its program gave back takes command lines again" { } test "the host is asked about a tty only where a command line is about to go" { + if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells const p = try Pardes.init(std.testing.allocator, .{ .shells = 3, .cols = 100, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} @@ -3235,9 +3277,9 @@ test "a host with no methods at all is a complete in-process pardes" { // the absent child is SILENT: the bytes are dropped, and nothing appears // on the pane's screen to suggest a program answered - const before = p.panes[0].?.terminal.?.vt.screens.active.cursor.y; + const before = pardes.Term.grid(p.panes[0].?.terminal).cursor_y; p.perform(.{ .write = .{ .pane = 0, .bytes = .from("ls\r") } }); - try std.testing.expectEqual(before, p.panes[0].?.terminal.?.vt.screens.active.cursor.y); + try std.testing.expectEqual(before, pardes.Term.grid(p.panes[0].?.terminal).cursor_y); // the clipboard round-trips through the in-process one try p.registers.put(gpa, '+', "copied", 0, 1, true); @@ -3352,6 +3394,7 @@ test "startup config overrides restored styling before initFromDump returns" { } test "restored terminals keep monotonic nonzero pane identities" { + if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells const gpa = std.testing.allocator; const source = try Pardes.init(gpa, .{ .shells = 3 }); defer source.deinit(); @@ -3646,6 +3689,7 @@ test "argv naming nothing boots an errors pane rather than failing the launch" { } test "raw terminal cursor obeys visibility without hiding modal and tag cursors" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); @@ -3690,6 +3734,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" } test "raw terminal cursor follows its active row only while that row is visible" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); @@ -3706,19 +3751,20 @@ test "raw terminal cursor follows its active row only while that row is visible" try std.testing.expectEqual(rect.x + config.GUTTER + 3, live.x); try std.testing.expectEqual(body_y + 2, live.y); - pardes.panes.terminal.scrollGrid(pane, -1); + pardes.Term.scroll(pane.terminal.?, -1); const scrolled = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(live.x, scrolled.x); try std.testing.expectEqual(live.y + 1, scrolled.y); - pardes.panes.terminal.scrollGrid(pane, -@as(i32, pane.rows)); + pardes.Term.scroll(pane.terminal.?, -@as(i32, pane.rows)); try std.testing.expect((try p.render(frame.allocator())).cursor == null); - pardes.panes.terminal.followOutput(pane); + pane.followOutput(); const returned = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(live.x, returned.x); try std.testing.expectEqual(live.y, returned.y); } test "the bare tty startup opens a text pane under the shell, unfocused" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .boot = .tty }); defer p.deinit(); try std.testing.expectEqual(Boot.tty, p.boot); @@ -3744,6 +3790,7 @@ test "the bare tty startup opens a text pane under the shell, unfocused" { } test "tty output follows only from the bottom" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell, opened by a key const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); defer p.deinit(); p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); @@ -3758,34 +3805,35 @@ test "tty output follows only from the bottom" { p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); - const bottom = pardes.panes.terminal.scrollbar(sp).offset; + const bottom = pardes.Term.grid(sp.terminal).offset; try std.testing.expect(bottom > 0); // Scrolled back, the reader stays put however much the shell prints. sp.scrollBy(-10); p.sync(); - const parked = pardes.panes.terminal.scrollbar(sp).offset; + const parked = pardes.Term.grid(sp.terminal).offset; try std.testing.expect(parked < bottom); for (60..70) |i| { var buf: [32]u8 = undefined; p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); - try std.testing.expectEqual(parked, pardes.panes.terminal.scrollbar(sp).offset); + try std.testing.expectEqual(parked, pardes.Term.grid(sp.terminal).offset); // Typing snaps back to live output, so nobody types blind. p.update(.{ .key = .{ .cp = 'x', .text = "x" } }); p.sync(); - try std.testing.expect(pardes.panes.terminal.scrollbar(sp).offset > parked); + try std.testing.expect(pardes.Term.grid(sp.terminal).offset > parked); // ...and from there output follows again. - const live = pardes.panes.terminal.scrollbar(sp).offset; + const live = pardes.Term.grid(sp.terminal).offset; p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = "tail\r\n" } }); p.sync(); - try std.testing.expect(pardes.panes.terminal.scrollbar(sp).offset > live); + try std.testing.expect(pardes.Term.grid(sp.terminal).offset > live); } test "an unasked desktop paste reaches a tty pane's program, not its buffer" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -3794,7 +3842,7 @@ test "an unasked desktop paste reaches a tty pane's program, not its buffer" { _ = test_api.ptyBytes(p, null, &buf); const pane = p.panes[0].?; - pardes.panes.terminal.enterTty(p, 0); + pardes.keys.enterTty(p, 0); // No request behind it: the window manager's own paste, or SDL answering a // Ctrl-Shift-V the desktop handled. It still has to reach the shell. p.update(.{ .paste = "ls -la" }); @@ -3804,6 +3852,7 @@ test "an unasked desktop paste reaches a tty pane's program, not its buffer" { } test "a paste larger than the effect ring reaches the program whole and in order" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -3811,7 +3860,7 @@ test "a paste larger than the effect ring reaches the program whole and in order const buf = try gpa.alloc(u8, 2 << 20); defer gpa.free(buf); _ = test_api.ptyBytes(p, null, buf); - pardes.panes.terminal.enterTty(p, 0); + pardes.keys.enterTty(p, 0); const text = try gpa.alloc(u8, 1536 * 1024); defer gpa.free(text); @@ -3838,6 +3887,7 @@ test "bytes for a terminal past what may wait for it are dropped and said, never } test "a bracketed paste larger than the ring still closes its bracket" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -3845,10 +3895,10 @@ test "a bracketed paste larger than the ring still closes its bracket" { const buf = try gpa.alloc(u8, 2 << 20); defer gpa.free(buf); _ = test_api.ptyBytes(p, null, buf); - pardes.panes.terminal.enterTty(p, 0); + pardes.keys.enterTty(p, 0); p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); - try std.testing.expect(pardes.panes.terminal.bracketedPaste(p.panes[0].?)); + try std.testing.expect(pardes.Term.modes(p.panes[0].?.terminal).bracketed_paste); const text = try gpa.alloc(u8, 1536 * 1024); defer gpa.free(text); @memset(text, 'z'); @@ -3860,6 +3910,7 @@ test "a bracketed paste larger than the ring still closes its bracket" { } test "a terminal's answer to its program waits behind the paste still queued for its pty" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -3867,7 +3918,7 @@ test "a terminal's answer to its program waits behind the paste still queued for const buf = try gpa.alloc(u8, 2 << 20); defer gpa.free(buf); _ = test_api.ptyBytes(p, null, buf); - pardes.panes.terminal.enterTty(p, 0); + pardes.keys.enterTty(p, 0); const text = try gpa.alloc(u8, 1536 * 1024); defer gpa.free(text); @@ -3886,6 +3937,7 @@ test "a terminal's answer to its program waits behind the paste still queued for } test "pasted bytes still queued at shutdown are freed, not leaked" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -3893,7 +3945,7 @@ test "pasted bytes still queued at shutdown are freed, not leaked" { const buf = try gpa.alloc(u8, 2 << 20); defer gpa.free(buf); _ = test_api.ptyBytes(p, null, buf); - pardes.panes.terminal.enterTty(p, 0); + pardes.keys.enterTty(p, 0); const text = try gpa.alloc(u8, 1536 * 1024); defer gpa.free(text); @@ -3903,6 +3955,7 @@ test "pasted bytes still queued at shutdown are freed, not leaked" { } test "leaving tty hides the prompt and keeps the command typed at it" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell, opened by a key const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); defer p.deinit(); @@ -3922,14 +3975,14 @@ test "leaving tty hides the prompt and keeps the command typed at it" { const rowOf = struct { fn at(pp: *Pardes, pane: *Pane, needle: []const u8) ?[]const u8 { - const rows = pardes.panes.terminal.shellRows(pp, pane) catch return null; + const rows = pardes.edit.shellRows(pp, pane) catch return null; for (rows) |r| if (std.mem.indexOf(u8, r, needle) != null) return r; return null; } }.at; const bodyRowOf = struct { fn at(pp: *Pardes, pane: *Pane, needle: []const u8) ?[]const u8 { - const body = pardes.panes.terminal.bodyText(pp.scratch.allocator(), pane) catch return null; + const body = @import("body_layer.zig").bodyText(pp.scratch.allocator(), pane) catch return null; var it = std.mem.splitScalar(u8, body, '\n'); while (it.next()) |r| if (std.mem.indexOf(u8, r, needle) != null) return r; return null; @@ -3968,6 +4021,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { } test "entering tty walks the shell cursor to the column clicked past the prompt" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell, opened by a key const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }); defer p.deinit(); @@ -3984,7 +4038,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" p.shell_rows.stale = true; // The command shows LEFT-HUGGED, so its column 3 is the '3'... - const rows = try pardes.panes.terminal.shellRows(p, sp); + const rows = try pardes.edit.shellRows(p, sp); var row: i32 = 0; const at = for (rows, 0..) |r, i| { if (std.mem.indexOf(u8, r, "0123456789") != null) break i; @@ -3998,7 +4052,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" sp.body.cur_col = 3; sp.body.cur_pinned = true; while (p.nextEffect()) |_| {} - pardes.panes.terminal.enterTty(p, shell); + pardes.keys.enterTty(p, shell); // The walk is arrow keys the shell understands. Seven lefts: readline's // cursor sits past the '9' and the click was on the '3'. |
