diff options
Diffstat (limited to 'src/Core.zig')
| -rw-r--r-- | src/Core.zig | 127 |
1 files changed, 67 insertions, 60 deletions
diff --git a/src/Core.zig b/src/Core.zig index 9a6e80d4..a3ace8f9 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -73,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; @@ -209,9 +208,6 @@ 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 = .{}, @@ -231,9 +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, -/// The directory a `plumb start`'s command runs in, while it runs -/// (Plumb.run): the message's wdir, which no pane need have. -exec_dir: ?[]const u8 = 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. @@ -253,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. @@ -274,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 @@ -369,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.Term.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 @@ -396,8 +396,8 @@ 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 = .{}, @@ -573,7 +573,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); @@ -764,8 +764,6 @@ 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); @@ -870,9 +868,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; } @@ -1001,7 +999,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; } @@ -1607,7 +1614,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); }, @@ -1711,7 +1718,6 @@ fn processDir(buf: *[limits.host_path_cap]u8) ?[]const u8 { /// The directory a word run from pane `id`'s text or tag runs in, or, /// from a header, the session's. pub fn execDir(p: *Pardes, id: usize) []const u8 { - if (p.exec_dir) |dir| return dir; if (p.exec_header) return p.sessionDir(); return paneDir(p.panes[id] orelse return p.sessionDir()); } @@ -1805,10 +1811,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. @@ -1873,7 +1876,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; @@ -1882,19 +1885,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 => { @@ -1918,7 +1925,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 { @@ -1997,7 +2004,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); @@ -2168,7 +2175,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, @@ -2740,7 +2747,7 @@ 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); } @@ -3079,7 +3086,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")); } @@ -3110,16 +3117,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; @@ -3244,9 +3251,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); @@ -3715,13 +3722,13 @@ 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); @@ -3767,31 +3774,31 @@ 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" { @@ -3803,7 +3810,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" }); @@ -3820,7 +3827,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); @@ -3854,10 +3861,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'); @@ -3876,7 +3883,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); @@ -3902,7 +3909,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); @@ -3931,14 +3938,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; @@ -3993,7 +4000,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; @@ -4007,7 +4014,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'. |
