summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Core.zig22
-rw-r--r--src/Term.zig44
-rw-r--r--src/edit.zig4
-rw-r--r--src/exec.zig6
-rw-r--r--src/gui/gui.zig4
-rw-r--r--src/keys.zig51
-rw-r--r--src/mouse.zig30
-rw-r--r--src/ninep/pty.zig6
-rw-r--r--src/pardes.zig5
-rw-r--r--src/term/terminal.zig196
-rw-r--r--test/kitty.zig16
-rw-r--r--test/panes.zig26
-rw-r--r--test/perf.zig14
-rw-r--r--test/replicas.zig2
14 files changed, 228 insertions, 198 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 2bf02c5d..700ab7ab 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -862,9 +862,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;
}
@@ -3098,10 +3098,10 @@ 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;
@@ -3791,7 +3791,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" });
@@ -3808,7 +3808,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);
@@ -3842,10 +3842,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');
@@ -3864,7 +3864,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);
@@ -3890,7 +3890,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);
@@ -3995,7 +3995,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'.
diff --git a/src/Term.zig b/src/Term.zig
index 41452757..504aef7a 100644
--- a/src/Term.zig
+++ b/src/Term.zig
@@ -77,3 +77,47 @@ pub const Grid = struct {
/// memory for its pin). Taped: a screen-state replica, which feeds
/// nothing, is told its authority's.
pub const Told = struct { rows: []const i32, erased: []const bool, cleared: bool, alive: bool, failed: bool };
+
+// ---- input ----
+
+/// One key for its program, as the program's keyboard protocol and modes
+/// ask for it, written out.
+pub const key = terminal.key;
+/// One mouse event for its program, as the mode and format it set ask for
+/// it; empty when the program does not hear of it.
+pub const mouse = terminal.mouse;
+/// A wheel turn for its program; null when the wheel is not the program's.
+pub const wheel = terminal.wheel;
+/// A paste as xterm makes one: three parts, the text between the brackets
+/// when the program set 2004.
+pub const paste = terminal.paste;
+/// The modes its program set that the core decides by (`Modes`).
+pub const modes = terminal.modes;
+/// How far left or right a click on the prompt line moves the shell's
+/// cursor, at the prompt the cursor is at.
+pub const promptMoves = terminal.promptMoves;
+
+/// The key a frontend read (Event.zig).
+pub const Key = @import("Event.zig").Key;
+pub const MouseMods = struct { shift: bool = false, alt: bool = false, ctrl: bool = false };
+pub const MouseButton = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right };
+pub const MouseAction = enum { press, release, motion };
+/// Cursor-key presses: so many left, so many right.
+pub const Moves = struct { left: usize = 0, right: usize = 0 };
+
+/// The modes a program set that the core decides by.
+pub const Modes = struct {
+ /// It tracks the mouse itself (1000, 1002, 1003).
+ mouse: bool = false,
+ /// ...every move of it (1003).
+ all_motion: bool = false,
+ /// A wheel over it is its own: it tracks the mouse, or it is on the
+ /// alternate screen with alternate scroll (1007).
+ wheel: bool = false,
+ /// It wants to hear focus in and out (1004).
+ focus: bool = false,
+ /// It wants its pastes bracketed (2004).
+ bracketed_paste: bool = false,
+ /// It has the alternate screen (1049).
+ alternate: bool = false,
+};
diff --git a/src/edit.zig b/src/edit.zig
index 5fbabc83..3881020a 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -105,11 +105,11 @@ pub fn clipRequest(p: *Pardes, id: usize, mode: Paste) void {
}
/// Text pasted, yanked or sent into the program at `id`, as xterm pastes
-/// (terminal.encodePaste).
+/// (Term.paste).
pub fn typeToTty(p: *Pardes, id: usize, pane: *const Pane, text: []const u8) void {
if (text.len == 0) return;
const cp = p.scratch.allocator().dupe(u8, text) catch |err| return p.reportError(id, "paste", err);
- for (panes.terminal.encodePaste(pane, cp)) |part| if (part.len > 0) p.emitWrite(id, part);
+ for (panes.Term.paste(pane.terminal, cp)) |part| if (part.len > 0) p.emitWrite(id, part);
}
pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void {
diff --git a/src/exec.zig b/src/exec.zig
index 69bbe162..d7fb19d8 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -601,7 +601,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
var said: pardes.Kind.Buf(128) = .{};
return p.setMessage(from, said.print("Repl: {d} bytes is more than can be sent at once; send less", .{n}));
}
- const pasted = panes.terminal.bracketedPaste(dst);
+ const pasted = panes.Term.modes(dst.terminal).bracketed_paste;
edit.typeToTty(p, to, dst, clean[0..n]);
// A Python block whose last line is indented, or a bare header, is not
// over at one Enter, pasted into 3.13's REPL or typed into the old one:
@@ -624,7 +624,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
dst.repl_enter_due_ns = clockNow(p) + repl_enter_wait_ns;
} else for (0..enters) |_| p.emitWrite(to, "\r");
// Line by line, a blank line inside a Python block ends the block.
- if (!panes.terminal.bracketedPaste(dst) and !dst.repl_warned and (if (dst.repl) |r| r.lang == python_lang else false) and
+ if (!panes.Term.modes(dst.terminal).bracketed_paste and !dst.repl_warned and (if (dst.repl) |r| r.lang == python_lang else false) and
std.mem.indexOfScalar(u8, text, '\n') != null)
{
dst.repl_warned = true;
@@ -772,7 +772,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
// saved cursor), mouse reports and bracketed paste off, the cursor
// shown, colours reset. (Not DECSTR: ghostty's stream does not
// implement it.)
- if (panes.terminal.onAlternateScreen(pane)) pane.feedOutput(p, "\x1b[?1049l");
+ if (panes.Term.modes(pane.terminal).alternate) pane.feedOutput(p, "\x1b[?1049l");
pane.feedOutput(p, "\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?2004l\x1b[?25h\x1b[0m");
echoCommand(p, pane, line);
pane.command_from = winid(p, src);
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index dbae12b5..4b956f52 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -624,7 +624,7 @@ const Gui = struct {
/// picture follows on a spring (Glide), never the other way round.
scroll_notch: i32 = 0,
/// A touchpad's fraction toward the next turn sent to a program that
- /// owns the wheel (terminal.ownsWheel).
+ /// owns the wheel (Term.Modes.wheel).
program_wheel: f32 = 0,
/// A trackpad's horizontal fraction toward the next turn (wheelAt).
program_wheel_x: f32 = 0,
@@ -2443,7 +2443,7 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
// touchpad's fraction of a notch too (pa_mouse.amount).
resetScroll(g);
in.post(.{ .mouse = .{ .button = if (w.y < 0) .wheel_down else .wheel_up, .kind = .press, .col = mc.col, .row = mc.row, .tag_hit = mc.tag_hit, .body_hit = mc.body_hit, .ctrl = w.mods.ctrl, .shift = w.mods.shift, .alt = w.mods.alt, .amount = @abs(w.y) } });
- } else if (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane)) {
+ } else if (!w.mods.shift and pane.isTerminal() and pardes.Term.modes(pane.terminal).wheel) {
// The program's (codex, htop, less): every whole turn goes
// to it, no glide, for nothing of ours moves. Shift keeps
// a terminal's wheel pardes's.
diff --git a/src/keys.zig b/src/keys.zig
index 7703d573..c4651be7 100644
--- a/src/keys.zig
+++ b/src/keys.zig
@@ -46,11 +46,52 @@ pub fn cycleMode(p: *Pardes, id: usize) void {
.normal => edit.enterInsert(p, &pane.body, .at, 1) catch |err| p.reportError(id, "edit", err),
.insert => {
edit.exitInsert(p, &pane.body);
- if (pane.isTerminal()) panes.terminal.enterTty(p, id);
+ if (pane.isTerminal()) enterTty(p, id);
},
}
}
+/// Raw tty mode, the keys the program's: the shell's cursor first moved to
+/// where the edit cursor was on its prompt line (cursor keys, as a click
+/// there would), unless the pointer holds a selection to keep.
+pub fn enterTty(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ const selected = pane.rawPointerText(pane.sel[@backingInt(config.select_button)]) != null;
+ if (!selected and pane.body.cur_pinned) if (pane.terminal) |state| {
+ const row = pane.gridRow(pane.body.cur_row) - @as(i32, @intCast(panes.Term.grid(state).offset));
+ if (panes.Term.promptMoves(state, row, pane.body.cur_col)) |moves| {
+ for (0..moves.left) |_| p.emitWrite(id, "\x1b[D");
+ for (0..moves.right) |_| p.emitWrite(id, "\x1b[C");
+ }
+ };
+ pane.body.mode = .tty;
+ pane.followOutput(); // entering raw mode is a request for the live shell
+ pane.body.vsel.active = false;
+ pane.body.nsel = 0;
+ // The raw renderer follows the live cursor. A captured mouse selection
+ // keeps its modal endpoint for the next return to editor mode.
+ pane.body.cur_pinned = selected;
+ pane.body.select = false;
+ pane.body.restore_cursor = false;
+ pane.body.sticky_col = -1;
+ pane.body.normal.clear();
+}
+
+/// One key for the program that owns a raw terminal, its pty write queued.
+pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
+ const pane = p.panes[id] orelse return;
+ const state = pane.terminal orelse return;
+ // A key's text has no bound of its own (an input method's commit, a
+ // paste as one key): past the stack's room the encoding grows on the
+ // heap, and emitWrite cuts it into writes.
+ var room: [256]u8 = undefined;
+ var first: std.heap.BufferFirstAllocator = .init(&room, p.gpa);
+ var out: std.Io.Writer.Allocating = .init(first.allocator());
+ defer out.deinit();
+ panes.Term.key(state, key, &out.writer) catch |err| return p.reportError(id, "key", err);
+ if (out.written().len > 0) p.emitWrite(id, out.written());
+}
+
/// One mode transition for the terminal tag command and the Ctrl-B chord.
pub fn toggleTty(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
@@ -62,7 +103,7 @@ pub fn toggleTty(p: *Pardes, id: usize) void {
if (pane.body.mode == .tty) {
pane.body.mode = .normal;
pane.body.normal.clear();
- } else panes.terminal.enterTty(p, id);
+ } else enterTty(p, id);
}
/// Type `keys` again (a macro, `.`): through the modal handling as
@@ -179,7 +220,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
pane.followOutput();
var plain = key;
plain.shift = false;
- return panes.terminal.forwardKey(p, p.view().active, plain);
+ return forwardKey(p, p.view().active, plain);
}
// Shift-Esc backs out of whatever the pane is in -- a prompt, insert
// mode, a pending count, a raw program -- to the previous pane, as
@@ -225,7 +266,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// Ctrl-V a black hole in every full-screen application.
if (p.registers.text(p.gpa, Registers.default)) |text| return edit.typeToTty(p, p.view().active, pane, text);
}
- return panes.terminal.forwardKey(p, p.view().active, key);
+ return forwardKey(p, p.view().active, key);
}
// A kind's pane that takes keys takes them all, as a raw terminal
// does; Esc too, first, when its kind is of 2.1 (a PDF's drops its
@@ -406,7 +447,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
edit.exitInsert(p, t)
else
edit.handleInsert(p, t, key),
- .tty => panes.terminal.forwardKey(p, p.view().active, key),
+ .tty => forwardKey(p, p.view().active, key),
}
// `.`'s log: the keys of the normal command that entered insert
// mode, then everything typed until it is left
diff --git a/src/mouse.zig b/src/mouse.zig
index 49e9927e..06f3a755 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -199,7 +199,7 @@ pub fn sameBodyCell(a: ?Mouse.BodyHit, b: ?Mouse.BodyHit) bool {
return first.serial == second.serial and first.row == second.row and first.col == second.col;
}
-/// A wheel over a terminal whose program owns it (`terminal.ownsWheel`:
+/// A wheel over a terminal whose program owns it (`Term.Modes.wheel`:
/// codex, htop, less) goes to the program as the program asked, one turn
/// per line, instead of scrolling a scrollback the alternate screen does
/// not have. Shift keeps it pardes's, as xterm's Shift does. False when
@@ -207,19 +207,19 @@ pub fn sameBodyCell(a: ?Mouse.BodyHit, b: ?Mouse.BodyHit) bool {
fn programWheel(p: *Pardes, id: usize, m: Mouse, col: u16, row: u16) bool {
if (m.shift) return false;
const pane = p.panes[id] orelse return false;
- if (!pane.isTerminal() or !panes.terminal.ownsWheel(pane)) return false;
+ if (!pane.isTerminal() or !panes.Term.modes(pane.terminal).wheel) return false;
const r = p.view().rects[id];
const body_y = p.bodyTop(pane, r);
const gcol = std.math.clamp(col -| (r.x + config.GUTTER), 0, pane.cols -| 1);
const grow = std.math.clamp(row -| body_y, 0, pane.rows -| 1);
var buf: [64]u8 = undefined;
- const wheel: panes.terminal.MouseButton = switch (m.button) {
+ const wheel: panes.Term.MouseButton = switch (m.button) {
.wheel_up => .wheel_up,
.wheel_down => .wheel_down,
.wheel_left => .wheel_left,
else => .wheel_right,
};
- const bytes = panes.terminal.wheelBytes(pane, &buf, wheel, gcol, grow, .{ .alt = m.alt, .ctrl = m.ctrl }) orelse return true;
+ const bytes = panes.Term.wheel(pane.terminal.?, &buf, wheel, gcol, grow, .{ .alt = m.alt, .ctrl = m.ctrl }) orelse return true;
for (0..@intCast(config.wheel_rows)) |_| p.emitWrite(id, bytes);
return true;
}
@@ -249,7 +249,7 @@ fn programCell(p: *const Pardes, id: usize, col: u16, row: u16) ?struct { col: i
/// A pane whose program tracks the mouse (1000, 1002, 1003, or X10's 9)
/// and has the keyboard's raw input: its clicks are the program's.
fn tracksMouse(pane: *const Pane) bool {
- return pane.isTerminal() and pane.body.mode == .tty and panes.terminal.reportsMouse(pane);
+ return pane.isTerminal() and pane.body.mode == .tty and panes.Term.modes(pane.terminal).mouse;
}
/// A program that tracks the mouse gets it over its grid, as xterm gives
@@ -300,7 +300,7 @@ pub fn kindLeave(p: *Pardes) void {
fn programMouse(p: *Pardes, m: Mouse) bool {
const v = p.view();
- const button: ?panes.terminal.MouseButton = switch (m.button) {
+ const button: ?panes.Term.MouseButton = switch (m.button) {
.left => .left,
.middle => .middle,
.right => .right,
@@ -309,7 +309,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
};
const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0;
const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, v.screen_w -| 1), .row = @min(m.row, v.screen_h -| 1) };
- var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
+ var mods: panes.Term.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
var buf: [64]u8 = undefined;
if (v.mouse_grab) |*grab| {
if (grab.unshift) mods.shift = false;
@@ -326,14 +326,14 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
const r = v.rects[grab.id];
const col: i32 = @as(i32, at.col) - @as(i32, r.x + config.GUTTER);
const row: i32 = @as(i32, at.row) - @as(i32, p.bodyTop(pane, r));
- const action: panes.terminal.MouseAction = switch (m.kind) {
+ const action: panes.Term.MouseAction = switch (m.kind) {
.press => .press,
.release => .release,
.drag, .motion => .motion,
};
if (m.kind == .press) grab.held |= bit;
if (m.kind == .release) grab.held &= ~bit;
- const bytes = panes.terminal.mouseBytes(pane, &buf, action, button, mods, col, row, grab.held != 0);
+ const bytes = panes.Term.mouse(pane.terminal.?, &buf, action, button, mods, col, row, grab.held != 0);
if (bytes.len > 0) p.emitWrite(grab.id, bytes);
if (grab.held == 0) v.mouse_grab = null;
return true;
@@ -357,7 +357,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
pane.focus = .body;
pane.closePrompt();
v.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program };
- const bytes = panes.terminal.mouseBytes(pane, &buf, .press, button, mods, cell.col, cell.row, true);
+ const bytes = panes.Term.mouse(pane.terminal.?, &buf, .press, button, mods, cell.col, cell.row, true);
if (bytes.len > 0) p.emitWrite(id, bytes);
return true;
},
@@ -365,11 +365,11 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
// pardes's.
.release, .drag => return false,
.motion => {
- const bytes = panes.terminal.mouseBytes(pane, &buf, .motion, null, mods, cell.col, cell.row, false);
+ const bytes = panes.Term.mouse(pane.terminal.?, &buf, .motion, null, mods, cell.col, cell.row, false);
if (bytes.len > 0) p.emitWrite(id, bytes);
// Under 1003 the move is the program's; below that pardes
// hovers as ever.
- return panes.terminal.tracksAllMotion(pane);
+ return panes.Term.modes(pane.terminal).all_motion;
},
}
}
@@ -461,13 +461,13 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
if (cut) return;
const y = p.registers.text(p.gpa, pardes.Registers.default) orelse return;
if (y.len == 0) return;
- if (panes.terminal.reportsMouse(pane)) {
+ if (panes.Term.modes(pane.terminal).mouse) {
// A click where the text goes, so the program's cursor is there.
const col = @max(0, pane.sel[sel_slot].c1);
const row = @max(0, pane.sel[sel_slot].r1 - @as(i32, pane.tag_rows));
var mb: [64]u8 = undefined;
- for ([_]panes.terminal.MouseAction{ .press, .release }) |action| {
- const bytes = panes.terminal.mouseBytes(pane, &mb, action, .left, .{}, col, row, action == .press);
+ for ([_]panes.Term.MouseAction{ .press, .release }) |action| {
+ const bytes = panes.Term.mouse(pane.terminal.?, &mb, action, .left, .{}, col, row, action == .press);
if (bytes.len > 0) p.emitWrite(s.id, bytes);
}
}
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index 2ef9c13d..8e71a2c9 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -241,7 +241,7 @@ pub fn writeRun(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
var name: [64]u8 = undefined;
if (p.hostForegroundName(id, &name)) |program|
answer(p, slot, "busy: {s} is running", .{program})
- else if (pardes.panes.terminal.onAlternateScreen(pane))
+ else if (pardes.Term.modes(pane.terminal).alternate)
answer(p, slot, "busy alternate screen", .{})
else
answer(p, slot, "busy", .{});
@@ -302,7 +302,7 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void {
// A prompt on the alternate screen (its program killed there): the
// emulator leaves it first, as a reused command pane does, so the
// run's output lands on the primary screen and is read whole.
- if (pardes.panes.terminal.onAlternateScreen(pane)) pane.feedOutput(p, "\x1b[?1049l");
+ if (pardes.Term.modes(pane.terminal).alternate) pane.feedOutput(p, "\x1b[?1049l");
p.emitWrite(id, slot.line);
p.emitWrite(id, "\r");
pardes.panes.terminal.noteCommand(pane, slot.line);
@@ -1023,7 +1023,7 @@ test "a run's answer says cut when its output's start is gone, and reads a bound
sh.put(p, c ++ "\x1b[?1049hhtop's screen\r\n");
_ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h });
sh.put(p, "\x1b]133;D;137;aid=pardes\x07" ++ prompt);
- try testing.expect(pardes.panes.terminal.onAlternateScreen(pane));
+ try testing.expect(pardes.Term.modes(pane.terminal).alternate);
try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(serialOf(p), .pty_status), 0, 64).bytes, " 0\n"));
h = sh.send(p, node);
sh.put(p, c ++ "after htop\r\n" ++ d ++ prompt);
diff --git a/src/pardes.zig b/src/pardes.zig
index 4628c07e..13456de6 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -80,6 +80,7 @@ pub const echo = @import("term/echo.zig");
pub const Kind = @import("Kind.zig");
/// The terminal, as the core calls it (src/term/ behind it).
pub const Term = @import("Term.zig");
+pub const keys = @import("keys.zig");
pub const Addon = @import("Addon.zig");
pub const dump = @import("dump.zig");
pub const lsp = @import("lsp/lsp.zig");
@@ -284,13 +285,13 @@ pub const builtin_rows: [std.enums.values(Builtin).len]Row = blk: {
namew = @max(namew, @tagName(b).len);
}
for (std.enums.values(Builtin), 0..) |b, i| {
- const keys = if (config.leader_path.get(b)) |path| leaderKeys(path) else "";
+ const leader = if (config.leader_path.get(b)) |path| leaderKeys(path) else "";
const rest = shortcuts(b);
const named = @tagName(b) ++ (if (rest.len == 0) "" else (&@as([namew - @tagName(b).len]u8, @splat(' '))) ++ " " ++ rest);
rows[i] = .{
.path = config.leader_path.get(b),
.cmd = b,
- .line = keys ++ (&@as([4 + keyw - keys.len]u8, @splat(' '))) ++ " " ++ named,
+ .line = leader ++ (&@as([4 + keyw - leader.len]u8, @splat(' '))) ++ " " ++ named,
};
}
const last = "\x7f";
diff --git a/src/term/terminal.zig b/src/term/terminal.zig
index 50fca2d0..02ae4b3c 100644
--- a/src/term/terminal.zig
+++ b/src/term/terminal.zig
@@ -322,8 +322,8 @@ pub const State = struct {
defer decoded.deinit(gpa);
out.* = .{ .gpa = gpa, .vt = decoded.toOwned(), .stream = undefined };
}
- if (comptime images_enabled) inline for (.{ .primary, .alternate }) |key| {
- if (out.vt.screens.get(key)) |screen| screen.kitty_images.image_limits = .allWithTempDir(tempDir());
+ if (comptime images_enabled) inline for (.{ .primary, .alternate }) |which| {
+ if (out.vt.screens.get(which)) |screen| screen.kitty_images.image_limits = .allWithTempDir(tempDir());
};
out.wire();
const reply = parts.reply[0..@min(parts.reply.len, out.reply.len)];
@@ -404,13 +404,13 @@ const LivePalette = struct {
for (&base, synthesized) |*dst, src| dst.* = asGhostRgb(src);
}
- const key: FilterPaletteKey = .{ .bg = bg, .fg = fg, .base = base };
- if (self.key) |old| if (std.meta.eql(old, key)) return &self.colors;
+ const wanted: FilterPaletteKey = .{ .bg = bg, .fg = fg, .base = base };
+ if (self.key) |old| if (std.meta.eql(old, wanted)) return &self.colors;
var seed = GColor.default;
for (base, 0..) |rgb, i| seed[i] = rgb;
self.colors = GColor.generate256Color(seed, .empty, bg, fg, false);
- self.key = key;
+ self.key = wanted;
return &self.colors;
}
};
@@ -620,16 +620,21 @@ pub fn replies(state: *State) []const u8 {
return state.reply[0..state.reply_len];
}
-/// DECSET 2004: the program wants its pastes bracketed.
-pub fn bracketedPaste(pane: *const Pane) bool {
- const state = pane.terminal orelse return false;
- return state.vt.modes.get(.bracketed_paste);
-}
-
-/// The program tracks the mouse itself, so a click in its body is its event.
-pub fn reportsMouse(pane: *const Pane) bool {
- const state = pane.terminal orelse return false;
- return state.vt.flags.mouse_event != .none;
+/// The modes its program set that the core decides by (`Term.Modes`).
+pub fn modes(state: ?*const State) Term.Modes {
+ const s = state orelse return .{};
+ const alternate = s.vt.screens.active_key == .alternate;
+ const mouse_event = s.vt.flags.mouse_event != .none;
+ return .{
+ .mouse = mouse_event,
+ .all_motion = s.vt.flags.mouse_event == .any,
+ // On the alternate screen, which has no scrollback, alternate
+ // scroll (DECSET 1007, on unless turned off) asks for arrow keys.
+ .wheel = mouse_event or (alternate and s.vt.modes.get(.mouse_alternate_scroll)),
+ .focus = s.vt.modes.get(.focus_event),
+ .bracketed_paste = s.vt.modes.get(.bracketed_paste),
+ .alternate = alternate,
+ };
}
/// A paste as xterm makes one (ghostty's encoder): the control bytes a
@@ -637,35 +642,10 @@ pub fn reportsMouse(pane: *const Pane) bool {
/// 2004's brackets early, NUL, ^C and the rest of xterm's list) become
/// spaces, then the text goes inside the brackets when the program set
/// 2004, else with its newlines as Returns. `text` is rewritten in place.
-pub fn encodePaste(pane: *const Pane, text: []u8) [3][]const u8 {
- return ghostty_vt.input.encodePaste(text, .{ .bracketed = bracketedPaste(pane) });
+pub fn paste(state: ?*const State, text: []u8) [3][]const u8 {
+ return ghostty_vt.input.encodePaste(text, .{ .bracketed = modes(state).bracketed_paste });
}
-/// DECSET 1004: the program wants to hear when it gains and loses focus.
-pub fn reportsFocus(pane: *const Pane) bool {
- const state = pane.terminal orelse return false;
- return state.vt.modes.get(.focus_event);
-}
-
-/// ...every move of it, a button down or not (1003).
-pub fn tracksAllMotion(pane: *const Pane) bool {
- const state = pane.terminal orelse return false;
- return state.vt.flags.mouse_event == .any;
-}
-
-/// A wheel over the program is the program's: it tracks the mouse, or it is
-/// on the alternate screen, which has no scrollback, with alternate scroll
-/// (DECSET 1007, on unless turned off) asking for arrow keys instead.
-pub fn ownsWheel(pane: *const Pane) bool {
- const state = pane.terminal orelse return false;
- return reportsMouse(pane) or
- (state.vt.screens.active_key == .alternate and state.vt.modes.get(.mouse_alternate_scroll));
-}
-
-pub const MouseMods = struct { shift: bool = false, alt: bool = false, ctrl: bool = false };
-pub const MouseButton = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right };
-pub const MouseAction = enum { press, release, motion };
-
/// One mouse event for the program, as xterm reports it (ctlseqs; ghostty's
/// encoder): the tracking mode it set (1000 clicks, 1002 drags, 1003 all
/// motion) decides whether it hears of it, the format it set (1006 SGR,
@@ -673,8 +653,7 @@ pub const MouseAction = enum { press, release, motion };
/// ctrl+16. `col`,`row` are the 0-based grid cell; a drag that left the
/// grid is reported clamped to its edge, motion only when the cell
/// changed. Empty when the program does not hear of it.
-pub fn mouseBytes(pane: *Pane, buf: *[64]u8, action: MouseAction, button: ?MouseButton, mods: MouseMods, col: i32, row: i32, any_pressed: bool) []const u8 {
- const state = pane.terminal orelse return &.{};
+pub fn mouse(state: *State, buf: *[64]u8, action: Term.MouseAction, button: ?Term.MouseButton, mods: Term.MouseMods, col: i32, row: i32, any_pressed: bool) []const u8 {
const input = ghostty_vt.input;
var writer = std.Io.Writer.fixed(buf);
var opts: input.MouseEncodeOptions = .{
@@ -714,17 +693,17 @@ pub fn mouseBytes(pane: *Pane, buf: *[64]u8, action: MouseAction, button: ?Mouse
/// The bytes a wheel turn at grid cell `col`,`row` (0-based) sends the
/// program: its mouse report while it tracks the mouse, else, on the
/// alternate screen, an arrow key in the cursor keys' mode (none for a
-/// sideways turn). Null when the wheel is not the program's (`ownsWheel`).
-pub fn wheelBytes(pane: *Pane, buf: *[64]u8, wheel: MouseButton, col: u16, row: u16, mods: MouseMods) ?[]const u8 {
- const state = pane.terminal orelse return null;
- if (!ownsWheel(pane)) return null;
+/// sideways turn). Null when the wheel is not the program's (`Modes.wheel`).
+pub fn wheel(state: *State, buf: *[64]u8, turn: Term.MouseButton, col: u16, row: u16, mods: Term.MouseMods) ?[]const u8 {
+ const now = modes(state);
+ if (!now.wheel) return null;
const m = &state.vt.modes;
- if (!reportsMouse(pane)) return switch (wheel) {
+ if (!now.mouse) return switch (turn) {
.wheel_up => if (m.get(.cursor_keys)) "\x1bOA" else "\x1b[A",
.wheel_down => if (m.get(.cursor_keys)) "\x1bOB" else "\x1b[B",
else => null,
};
- return mouseBytes(pane, buf, .press, wheel, mods, col, row, false);
+ return mouse(state, buf, .press, turn, mods, col, row, false);
}
/// The whole scrollback as plain text, `gpa`-owned: what a terminal's body
@@ -891,8 +870,8 @@ pub fn feed(state: *State, bytes: []const u8, track: []const i32, rows: []i32, e
return .{ .rows = rows[0..0], .erased = erased[0..0], .cleared = false, .alive = true, .failed = false };
}
const screens = &state.vt.screens;
- const key = screens.active_key;
- const generation = screens.generation(key);
+ const active = screens.active_key;
+ const generation = screens.generation(active);
const pages = &screens.active.pages;
var failed = false;
var room: [512]RowPin = undefined;
@@ -910,7 +889,7 @@ pub fn feed(state: *State, bytes: []const u8, track: []const i32, rows: []i32, e
ingest(state, bytes);
const cleared = state.vt.flags.dirty.clear;
// RIS can destroy the alternate screen and every pin it owned.
- const alive: ?*ghostty_vt.PageList = if (screens.generation(key) == generation) pages else null;
+ const alive: ?*ghostty_vt.PageList = if (screens.generation(active) == generation) pages else null;
for (pins, rows[0..track.len], erased[0..track.len]) |pin, *row, *gone| {
row.* = pinnedRow(alive, pin);
gone.* = alive != null and pin.pin != null and pin.pin.?.garbage;
@@ -919,12 +898,6 @@ pub fn feed(state: *State, bytes: []const u8, track: []const i32, rows: []i32, e
return .{ .rows = rows[0..track.len], .erased = erased[0..track.len], .cleared = cleared, .alive = alive != null, .failed = failed };
}
-/// A full-screen program has the emulator on its alternate screen.
-pub fn onAlternateScreen(pane: *const Pane) bool {
- const state = pane.terminal orelse return false;
- return state.vt.screens.active_key == .alternate;
-}
-
/// Whether a new terminal's greeting may be typed now: only at the shell's
/// first prompt (pardes's own marks: no command started; a prompt drawn
/// again for a resize is the same first prompt), with nothing
@@ -1022,18 +995,16 @@ pub fn promptInputEmpty(pane: *const Pane) bool {
return true;
}
-/// Encode one key for the program that owns a raw terminal and queue its pty
-/// write, respecting the application's keyboard protocol and terminal modes.
-pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
- const pane = p.panes[id] orelse return;
- const state = pane.terminal orelse return;
+/// One key for its program, as the program's keyboard protocol and modes
+/// ask for it, written to `out`.
+pub fn key(state: *State, k: Key, out: *std.Io.Writer) !void {
const input = ghostty_vt.input;
const function_keys = comptime keys: {
var keys: [Key.f25 - Key.f1 + 1]input.Key = undefined;
- for (&keys, 1..) |*k, n| k.* = @field(input.Key, std.fmt.comptimePrint("f{d}", .{n}));
+ for (&keys, 1..) |*slot, n| slot.* = @field(input.Key, std.fmt.comptimePrint("f{d}", .{n}));
break :keys keys;
};
- const physical: input.Key = switch (key.cp) {
+ const physical: input.Key = switch (k.cp) {
Key.enter => .enter,
Key.backspace => .backspace,
Key.tab => .tab,
@@ -1052,32 +1023,25 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
Key.scroll_lock => .scroll_lock,
Key.pause => .pause,
Key.menu => .context_menu,
- Key.f1...Key.f25 => function_keys[key.cp - Key.f1],
- else => if (key.cp < 128) input.Key.fromASCII(@intCast(key.cp)) orelse .unidentified else .unidentified,
+ Key.f1...Key.f25 => function_keys[k.cp - Key.f1],
+ else => if (k.cp < 128) input.Key.fromASCII(@intCast(k.cp)) orelse .unidentified else .unidentified,
};
var utf8: [4]u8 = undefined;
- const text_cp = if (key.shift and key.cp >= 'a' and key.cp <= 'z') key.cp - 'a' + 'A' else key.cp;
+ const text_cp = if (k.shift and k.cp >= 'a' and k.cp <= 'z') k.cp - 'a' + 'A' else k.cp;
// A key with no text of its own types its code point only when that
// is a character: the kitty keyboard protocol numbers function and
// modifier keys in the private use area (F3 is U+E016), and a shell
// was typed those as junk.
- const text = if (key.text.len > 0) key.text else if (key.cp >= 32 and key.cp < Key.up and key.cp != Key.backspace and !(key.cp >= 0xE000 and key.cp <= 0xF8FF))
+ const text = if (k.text.len > 0) k.text else if (k.cp >= 32 and k.cp < Key.up and k.cp != Key.backspace and !(k.cp >= 0xE000 and k.cp <= 0xF8FF))
utf8[0 .. std.unicode.utf8Encode(text_cp, &utf8) catch return]
else
"";
- // A key's text has no bound of its own (an input method's commit, a
- // paste as one key): past the stack's room the encoding grows on the
- // heap, and emitWrite cuts it into writes.
- var room: [256]u8 = undefined;
- var first: std.heap.BufferFirstAllocator = .init(&room, p.gpa);
- var out: std.Io.Writer.Allocating = .init(first.allocator());
- defer out.deinit();
- input.encodeKey(&out.writer, .{
+ try input.encodeKey(out, .{
.key = physical,
- .mods = .{ .ctrl = key.ctrl, .alt = key.alt, .shift = key.shift },
- .consumed_mods = .{ .shift = key.text.len > 0 and key.shift },
+ .mods = .{ .ctrl = k.ctrl, .alt = k.alt, .shift = k.shift },
+ .consumed_mods = .{ .shift = k.text.len > 0 and k.shift },
.utf8 = text,
- .unshifted_codepoint = if (key.cp >= 'A' and key.cp <= 'Z') key.cp - 'A' + 'a' else if (key.cp < Key.up) key.cp else 0,
+ .unshifted_codepoint = if (k.cp >= 'A' and k.cp <= 'Z') k.cp - 'A' + 'a' else if (k.cp < Key.up) k.cp else 0,
}, options: {
var opts = input.KeyEncodeOptions.fromTerminal(&state.vt);
// fromTerminal cannot know this one and says so, defaulting to
@@ -1091,49 +1055,32 @@ pub fn forwardKey(p: *Pardes, id: usize, key: Key) void {
// the floor and forwards Alt-n to the child as a bare `n`.
opts.macos_option_as_alt = .true;
break :options opts;
- }) catch |err| return p.reportError(id, "key", err);
- if (out.written().len > 0) p.emitWrite(id, out.written());
+ });
}
-pub fn enterTty(p: *Pardes, id: usize) void {
- const pane = p.panes[id] orelse return;
- const selected = pane.rawPointerText(pane.sel[@backingInt(config.select_button)]) != null;
- if (!selected and pane.terminal != null and pane.body.cur_pinned and pane.terminal.?.vt.cursorIsAtPrompt()) handoff: {
- const screen = pane.terminal.?.vt.screens.active;
- const goff: i32 = @intCast(screen.pages.scrollbar().offset);
- const vp_row = pane.gridRow(pane.body.cur_row) - goff;
- if (vp_row < 0) break :handoff;
-
- var grid_col: i32 = @max(0, pane.body.cur_col);
- if (screen.pages.pin(.{ .viewport = .{ .x = 0, .y = @intCast(vp_row) } })) |row_pin| {
- if (row_pin.rowAndCell().row.semantic_prompt != .none) switch (promptCut(row_pin)) {
- .cut => |cols| grid_col += @intCast(cols),
- .keep, .blank => {},
- };
- }
- const click_pin = screen.pages.pin(.{
- .viewport = .{ .x = @intCast(grid_col), .y = @intCast(vp_row) },
- }) orelse break :handoff;
- const cursor_pin = screen.cursor.page_pin.*;
- var prompts = cursor_pin.promptIterator(.left_up, null);
- const prompt_pin = prompts.next() orelse break :handoff;
- if (click_pin.before(prompt_pin)) break :handoff;
- const moves = screen.promptClickMove(click_pin);
- for (0..moves.left) |_| p.emitWrite(id, "\x1b[D");
- for (0..moves.right) |_| p.emitWrite(id, "\x1b[C");
+/// How many cells left or right of the cursor a click on viewport row
+/// `row`, column `col` of the text shown (the prompt cut off) is, at the
+/// prompt the cursor is at: what moves the shell's cursor there. Null
+/// when the cursor is at no prompt, or the click is before the prompt.
+pub fn promptMoves(state: *State, row: i32, col: i32) ?Term.Moves {
+ if (!state.vt.cursorIsAtPrompt() or row < 0) return null;
+ const screen = state.vt.screens.active;
+ var grid_col: i32 = @max(0, col);
+ if (screen.pages.pin(.{ .viewport = .{ .x = 0, .y = @intCast(row) } })) |row_pin| {
+ if (row_pin.rowAndCell().row.semantic_prompt != .none) switch (promptCut(row_pin)) {
+ .cut => |cols| grid_col += @intCast(cols),
+ .keep, .blank => {},
+ };
}
-
- pane.body.mode = .tty;
- pane.followOutput(); // entering raw mode is a request for the live shell
- pane.body.vsel.active = false;
- pane.body.nsel = 0;
- // The raw renderer follows the live cursor. A captured mouse selection
- // keeps its modal endpoint for the next return to editor mode.
- pane.body.cur_pinned = selected;
- pane.body.select = false;
- pane.body.restore_cursor = false;
- pane.body.sticky_col = -1;
- pane.body.normal.clear();
+ const click_pin = screen.pages.pin(.{
+ .viewport = .{ .x = @intCast(grid_col), .y = @intCast(row) },
+ }) orelse return null;
+ const cursor_pin = screen.cursor.page_pin.*;
+ var prompts = cursor_pin.promptIterator(.left_up, null);
+ const prompt_pin = prompts.next() orelse return null;
+ if (click_pin.before(prompt_pin)) return null;
+ const moves = screen.promptClickMove(click_pin);
+ return .{ .left = moves.left, .right = moves.right };
}
// Returned slices remain valid until the next cache rebuild or reset.
@@ -2254,8 +2201,7 @@ test "document construction allocates only the pane and has inert terminal defau
try std.testing.expect(!failing.has_induced_failure);
try std.testing.expectEqual(@as(usize, @sizeOf(Pane)), failing.allocated_bytes);
try std.testing.expectEqual(Term.Grid{}, grid(pane.terminal));
- try std.testing.expect(!bracketedPaste(pane));
- try std.testing.expect(!reportsMouse(pane));
+ try std.testing.expectEqual(Term.Modes{}, modes(pane.terminal));
try std.testing.expect(!promptInputReady(pane));
pane.scrollBy(100);
pane.followOutput();
@@ -2724,7 +2670,7 @@ test "terminal Filter holds every projected foreground off the page" {
p.settings.theme = @intCast(t);
var fc = FilteredColors.init(p, &pane.terminal.?.vt);
var refused: usize = 0;
- for (fc.target, 0..) |projected, key| {
+ for (fc.target, 0..) |projected, slot| {
const ink = fc.legible(projected);
try testing.expect(ink.contrast(fc.default_bg) >= config.tty_filter_min_contrast);
if (!ink.eql(projected)) {
@@ -2735,7 +2681,7 @@ test "terminal Filter holds every projected foreground off the page" {
}
// The key a background asks for is handed back untouched, including
// the one whose value is the page itself.
- try testing.expect(fc.keyedRgb(GColor.default[key]).eql(fc.target[fc.nearestKey(GColor.default[key])]));
+ try testing.expect(fc.keyedRgb(GColor.default[slot]).eql(fc.target[fc.nearestKey(GColor.default[slot])]));
}
// Every curated theme owns at least one collapsing key — that is why
// the floor exists — and the floor must not be flattening the palette.
diff --git a/test/kitty.zig b/test/kitty.zig
index 7b5347e0..4341677e 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -66,7 +66,7 @@ const Rig = struct {
fn init(shells: u8) !Rig {
// f=100 decodes through wuffs, its resize through stb_image_resize,
// which the shells start at launch.
- pardes.TerminalImages.start(gpa);
+ pardes.Term.start(gpa);
// ghostty warns of every refused command; the refusals are the point.
std.testing.log_level = .err;
// A core boots one shell or the classic three.
@@ -86,7 +86,7 @@ const Rig = struct {
for (&r.read) |*b| b.deinit(gpa);
r.frame.deinit();
r.p.deinit();
- pardes.TerminalImages.stop();
+ pardes.Term.stop();
}
fn drain(r: *Rig) void {
@@ -642,14 +642,14 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo
try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].dst.y);
// A narrower pane reflows the text; the image stays on its row.
const pane = r.pane(0);
- terminal.resizeGrid(pane, 40, pane.rows);
+ pane.resizeGrid(40, pane.rows);
const text = try terminal.screenTextAlloc(pane, r.frame.allocator());
var row: usize = 0;
var lines = std.mem.splitScalar(u8, text, '\n');
while (lines.next()) |line| : (row += 1) if (std.mem.startsWith(u8, line, "marker")) break;
const drawn = try r.placesOf(10);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
- const viewport_top: usize = @intCast(terminal.gridOffset(pane));
+ const viewport_top: usize = pardes.Term.grid(pane.terminal).offset;
try std.testing.expectEqual(o.y + @as(u16, @intCast(row - viewport_top)), drawn[0].dst.y);
}
@@ -822,7 +822,7 @@ test "kitty: an animation's frames play" {
// Stopped (s=1), nothing more to wake for.
r.feed(0, apc("a=a,i=70,s=1,q=2", ""));
_ = try r.places();
- try std.testing.expectEqual(@as(?u64, null), terminal.animationDueMs(r.pane(0)));
+ try std.testing.expectEqual(@as(?u64, null), pardes.Term.due(r.pane(0).terminal.?));
}
test "kitty: a placement relative to another (P=, Q=) is drawn at its parent's cell plus H/V" {
@@ -1168,7 +1168,7 @@ fn fuzzRun(seed: u64, steps: usize, trace: bool) !bool {
r.p.update(.{ .resize = .{ .cols = cols, .rows = rows, .cell_pixels = .{ .w = 1 + rng.uintLessThan(u16, 30), .h = 1 + rng.uintLessThan(u16, 60) } } });
r.drain();
},
- 1 => terminal.resizeGrid(r.pane(0), 1 + rng.uintLessThan(u16, 120), 1 + rng.uintLessThan(u16, 40)),
+ 1 => r.pane(0).resizeGrid(1 + rng.uintLessThan(u16, 120), 1 + rng.uintLessThan(u16, 40)),
2, 3 => {
const drawn = try r.places();
if (trace) std.debug.print(" {d} places, {d} placements, {d} images\n", .{ drawn.len, r.placementCount(0), r.storage(0).images.count() });
@@ -1225,13 +1225,13 @@ test "kitty: scrolled back by pardes, an image shows on its row; scrolled forwar
r.feed(0, &nl);
try std.testing.expectEqual(@as(usize, 0), (try r.placesOf(20)).len);
// Back to the top of the history: the marker row is the body's first.
- terminal.scrollGrid(pane, -1000);
+ pardes.Term.scroll(pane.terminal.?, -1000);
const o = r.origin(0);
const drawn = try r.placesOf(20);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
try std.testing.expectEqual(o.y, drawn[0].dst.y);
try std.testing.expectEqual(o.x + 6, drawn[0].dst.x);
- terminal.followOutput(pane);
+ pane.followOutput();
try std.testing.expectEqual(@as(usize, 0), (try r.placesOf(20)).len);
}
diff --git a/test/panes.zig b/test/panes.zig
index 001441a8..0a5674af 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -614,7 +614,7 @@ const TtySelectionTests = struct {
const pane = p.panes[0].?;
try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode);
if (bracketed) p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } });
- try std.testing.expectEqual(bracketed, panes.terminal.bracketedPaste(pane));
+ try std.testing.expectEqual(bracketed, pardes.Term.modes(pane.terminal).bracketed_paste);
try p.registers.put(p.gpa, '"', "one\ntwo", 0, 1, true); // what a `y` anywhere left behind
var buf: [256]u8 = undefined;
_ = childInput(p, &buf);
@@ -972,7 +972,7 @@ test "terminal overlay recoloring never materializes unrelated history" {
_ = try p.render(frame.allocator());
try testing.expect(p.shell_rows.pane == null);
- pane.ovl.?.row = panes.terminal.gridOffset(pane);
+ pane.ovl.?.row = @intCast(pardes.Term.grid(pane.terminal).offset);
p.gpa.free(pane.ovl.?.text);
pane.ovl.?.text = try p.gpa.dupe(u8, "caf\xc3\xa9 \xe7\x95\x8c");
_ = frame.reset(.retain_capacity);
@@ -1001,9 +1001,9 @@ test "terminal output keeps following new rows after scrollback eviction" {
for (0..3) |phase| {
if (phase > 0) {
pane.body.mode = .normal;
- panes.terminal.scrollGrid(pane, -30);
+ pardes.Term.scroll(pane.terminal.?, -30);
try std.testing.expect(pages.scrollbar().offset < pages.scrollbar().total - pane.rows);
- panes.terminal.enterTty(p, 0);
+ pardes.keys.enterTty(p, 0);
}
for (phase * 20_000..(phase + 1) * 20_000) |n| {
var buf: [64]u8 = undefined;
@@ -1123,7 +1123,7 @@ test "terminal edits and undo survive partial history clearing and whole-screen
if (action == .hidden_undo) {
gpa.free(pane.ovl.?.text);
pane.ovl = null;
- panes.terminal.enterTty(p, 0);
+ pardes.keys.enterTty(p, 0);
}
const bytes = switch (action) {
.clear_history, .partial_clear_history => "\x1b[3J",
@@ -1171,12 +1171,12 @@ test "terminal lower scroll regions do not move edits above them" {
pane.body.cur_row = 1;
pane.body.cur_pinned = true;
try panes.terminal.pushUndo(p, pane);
- const total = panes.terminal.scrollbar(pane).total;
+ const total = pardes.Term.grid(pane.terminal).total;
var setup: [64]u8 = undefined;
const bytes = try std.fmt.bufPrint(&setup, "\x1b[4;{d}r\x1b[{d};1H", .{ pane.rows, pane.rows });
p.update(.{ .output = .{ .pane = 0, .bytes = bytes } });
p.update(.{ .output = .{ .pane = 0, .bytes = std.mem.asBytes(&@as([50][6]u8, @splat("tail\r\n".*))) } });
- try std.testing.expectEqual(total, panes.terminal.scrollbar(pane).total);
+ try std.testing.expectEqual(total, pardes.Term.grid(pane.terminal).total);
try std.testing.expectEqual(@as(i32, 1), pane.ovl.?.row);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
try std.testing.expectEqual(@as(i32, 1), pane.body.ed_undo[0].ovl.?.row);
@@ -2322,11 +2322,9 @@ const TerminalTests = struct {
// Tests asserting raw ANSI indices explicitly select helix, whose palette
// is inherited. Native-palette coverage lives in the overlay/eviction and
// trailing-blank tests and checks their concrete RGB values instead.
- const gridOffset = panes.terminal.gridOffset;
- const scrollGrid = panes.terminal.scrollGrid;
const promptInputReady = panes.terminal.promptInputReady;
- const forwardKey = panes.terminal.forwardKey;
- const enterTty = panes.terminal.enterTty;
+ const forwardKey = pardes.keys.forwardKey;
+ const enterTty = pardes.keys.enterTty;
// Align normal-mode glyphs with the VT grid and compare their styles.
fn modeStyleDiffs(p: *Pardes, pane: *Pane, gpa: std.mem.Allocator, note: []const u8) !usize {
@@ -2699,14 +2697,14 @@ const TerminalTests = struct {
p.update(.{ .output = .{ .pane = 0, .bytes = bytes } });
}
p.shell_rows.stale = true;
- scrollGrid(pane, -20);
+ pardes.Term.scroll(pane.terminal.?, -20);
// ONE buffer line standing in for SIX shell rows: everything below slides
// UP five, so the last rows of the body resolve past the viewport's bottom
// edge. `PageList.pin` answers for those rows anyway — it walks down the
// pagelist, not the viewport — so without a bound of its own this pass
// painted the scrollback's colours onto rows the text pass left blank.
- const anchor = gridOffset(pane);
+ const anchor: i32 = @intCast(pardes.Term.grid(pane.terminal).offset);
pane.ovl = .{ .row = anchor, .rows = 6, .text = try p.gpa.dupe(u8, "one") };
p.shell_rows.stale = true;
@@ -2971,7 +2969,7 @@ const TerminalTests = struct {
// a buffer whose covered span STRADDLES the viewport top is an ordinary
// state. tty mode does not apply the buffer, so it must not be moved by one
// either — and `surfRow`/`gridRow` are not inverses across that span.
- const anchor = gridOffset(pane);
+ const anchor: i32 = @intCast(pardes.Term.grid(pane.terminal).offset);
pane.ovl = .{ .row = anchor - 1, .rows = 4, .text = try p.gpa.dupe(u8, "one\ntwo") };
p.shell_rows.stale = true;
_ = frame.reset(.retain_capacity);
diff --git a/test/perf.zig b/test/perf.zig
index 205fcd24..b8514d26 100644
--- a/test/perf.zig
+++ b/test/perf.zig
@@ -315,12 +315,12 @@ fn measureCreation(io: std.Io, reps: usize, json: bool) !void {
const allocator = counter.allocator();
const begin = nowNs();
const pane = if (terminal)
- try pardes.panes.terminal.create(allocator, screen_cols, screen_rows)
+ try pardes.panes.createTerminal(allocator, screen_cols, screen_rows)
else
- try pardes.panes.terminal.createDoc(allocator, screen_cols, screen_rows);
+ try pardes.panes.createDoc(allocator, screen_cols, screen_rows);
const constructed = nowNs();
const retained = counter.live;
- pardes.panes.terminal.deinitEmulator(pane, allocator);
+ if (pane.terminal) |state| pardes.Term.close(state, allocator);
allocator.destroy(pane);
const destroyed = nowNs();
if (counter.live != 0) return error.LeakedPaneMemory;
@@ -814,7 +814,7 @@ fn checkTerminalTail(core: *pardes.Pardes, surface: *pardes.Surface, batch: usiz
const pane = core.panes[0] orelse return error.MissingTerminal;
const rect = core.view().rects[0];
const x = rect.x + pardes.config.GUTTER;
- const y = rect.y + pardes.BOX_H + pardes.panes.terminal.gridCursor(pane).y;
+ const y = rect.y + pardes.BOX_H + pardes.Term.grid(pane.terminal).cursor_y;
var expected_buffer: [32]u8 = undefined;
const expected = try std.fmt.bufPrint(&expected_buffer, "TURN {d:0>10} READY", .{batch});
for (expected, 0..) |byte, col| {
@@ -889,7 +889,7 @@ fn measureUndoOutput(core: *pardes.Pardes, counter: *Allocations, arena: *std.he
for (pane.body.ed_undo[0..pane.body.ed_undo_len]) |snapshot| if (snapshot.ovl) |overlay| core.gpa.free(overlay.text);
pane.body.ed_undo_len = 0;
}
- pardes.panes.terminal.enterTty(core, 0);
+ pardes.keys.enterTty(core, 0);
pump(core);
const tracked_before = pages.countTrackedPins();
const start = try pages.trackPin(pages.pin(.{ .screen = .{ .y = @intCast(first) } }).?);
@@ -1001,7 +1001,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
}
const stream_wall_ns = nowNs() - stream_begin;
const live_after_output = counter.live;
- const first_row = @as(i32, @intCast(state.vt.screens.active.pages.scrollbar().offset)) + @as(i32, pardes.panes.terminal.gridCursor(pane).y);
+ const first_row = @as(i32, @intCast(state.vt.screens.active.pages.scrollbar().offset)) + @as(i32, pardes.Term.grid(pane.terminal).cursor_y);
_ = arena.reset(.retain_capacity);
const modal_begin = nowNs();
core.update(.{ .key = .{ .cp = core.opts.tty_toggle, .ctrl = true } });
@@ -1049,7 +1049,7 @@ fn measureTerminalSession(io: std.Io, mib: usize, reps: usize, json: bool) !void
const begin = nowNs();
core.update(.{ .output = .{ .pane = 0, .bytes = update } });
pump(core);
- const cursor_row = pardes.panes.terminal.gridOffset(pane) + @as(i32, pardes.panes.terminal.gridCursor(pane).y);
+ const cursor_row = @as(i32, @intCast(pardes.Term.grid(pane.terminal).offset)) + @as(i32, pardes.Term.grid(pane.terminal).cursor_y);
pane.ovl.?.row = if (phase == 0) 0 else cursor_row - 1;
pane.body.cur_row = pane.ovl.?.row;
pane.body.cur_col = 0;
diff --git a/test/replicas.zig b/test/replicas.zig
index 56e08607..8035e051 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -516,7 +516,7 @@ fn sendUnit(q: *std.PriorityQueue(Msg, void, Msg.order), n: *u64, unit: []const
}
screens.filled(core);
// The sizes its steps gave terminals, after their rows (Peers.unit).
- pardes.panes.terminal.resizeDeferred(core);
+ pardes.panes.resizeDeferred(core);
totals.unit_bytes += unit.len * down.len;
if (flooding) totals.flood_unit_bytes += unit.len * down.len;
for (down, 1..) |*l, who| {