summaryrefslogtreecommitdiff
path: root/src/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core.zig')
-rw-r--r--src/Core.zig107
1 files changed, 58 insertions, 49 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 9a6e80d4..7d8cfb0e 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;
@@ -253,7 +252,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.
@@ -369,10 +368,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 +395,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 +572,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);
@@ -870,9 +869,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 +1000,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 +1615,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);
},
@@ -1805,10 +1813,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 +1878,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 +1887,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 +1927,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 +2006,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 +2177,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 +2749,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 +3088,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 +3119,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 +3253,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 +3724,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 +3776,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 +3812,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 +3829,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 +3863,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 +3885,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 +3911,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 +3940,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 +4002,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 +4016,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'.