summaryrefslogtreecommitdiff
path: root/core/term
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 22:15:16 -0300
committerGabriel Schneider <[email protected]>2026-11-19 22:26:54 -0300
commitba10cc4ff30d08d27ad35576df04a03282b6521b (patch)
treee367489aa56f36d71485ce07b4022b512139a94c /core/term
parent98b2bc05cd7b6c78952600029939bbc44c5fc56b (diff)
downloadpardes-ba10cc4ff30d08d27ad35576df04a03282b6521b.tar.gz
pardes-ba10cc4ff30d08d27ad35576df04a03282b6521b.zip
Term: the two things a speculation writes into a terminal and no rollback puts back move into the pane, which the copy holds and the digest covers: the cell its program last heard the mouse at (Pane.term_mouse, handed to Term.mouse and Term.wheel, which ghostty's encoder reads and writes) and its kitty graphics as glyph art (Pane.term_petscii, which the Petscii builtin flips and the images' draw takes in ImagesAt): the sizing's table (reports/pardes-term-bytes.md, section 1; the brief's step 1c); Parts loses both (a dump of an older build carries them and they are passed over by name: a terminal's Petscii chosen before an Upgrade is off after it), Ops loses petscii and togglePetscii; term-test 17/17, core-test 848/991 (143 skipped), shell-test 1027/1030
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/term')
-rw-r--r--core/term/TerminalImages.zig9
-rw-r--r--core/term/term.zig2
-rw-r--r--core/term/terminal.zig35
3 files changed, 12 insertions, 34 deletions
diff --git a/core/term/TerminalImages.zig b/core/term/TerminalImages.zig
index feba5ddc..d0d364a1 100644
--- a/core/term/TerminalImages.zig
+++ b/core/term/TerminalImages.zig
@@ -24,9 +24,6 @@ const image_decode_pixels: usize = 64 * 1024 * 1024;
/// oldest past this): a 4K picture in RGBA, with room for a second.
pub const storage_limit = 64 * 1024 * 1024;
-/// This pane asks for its images as glyph art even where pixels could be
-/// drawn (the Petscii builtin).
-petscii: bool = false,
/// Pixels in RGBA for images ghostty-vt holds in another format (RGB,
/// grey): only for images on screen, dropped the frame they are not.
/// The emulator's own allocator's, as the emulator is (`draw`'s `own`):
@@ -191,7 +188,7 @@ pub fn draw(
const bottom = pages.getBottomRight(.viewport) orelse return;
const cw: u32 = @max(1, where.cell_w);
const ch: u32 = @max(1, where.cell_h);
- const ctx: Ctx = .{ .ti = ti, .own = own, .gpa = gpa, .out = out, .pane = where.pane, .serial = where.serial, .tx = where.tx, .body_y = where.body_y, .cols = where.cols, .rows_of = rows_of, .cw = cw, .ch = ch };
+ const ctx: Ctx = .{ .ti = ti, .own = own, .gpa = gpa, .out = out, .pane = where.pane, .serial = where.serial, .tx = where.tx, .body_y = where.body_y, .cols = where.cols, .rows_of = rows_of, .cw = cw, .ch = ch, .glyph = where.petscii };
// Handed on lowest z first (the storage's order is a hash map's), the
// order a shell draws them in; equal z keeps the order they came in.
const first = out.items.len;
@@ -283,6 +280,8 @@ const Ctx = struct {
rows_of: []const ?u16,
cw: u32,
ch: u32,
+ /// Its images as glyph art (the pane's Petscii).
+ glyph: bool,
/// Draw `src` of `img` over `dst`, one cell row of it at a time: a row
/// is shown, or not, or shown elsewhere, as the body lays it out.
@@ -323,7 +322,7 @@ const Ctx = struct {
},
.key = plain.Placement.keyOf(ctx.serial, img.id, @truncate(img.generation)),
.z = z,
- .art = .{ .glyph = ctx.ti.petscii },
+ .art = .{ .glyph = ctx.glyph },
}) catch {};
}
}
diff --git a/core/term/term.zig b/core/term/term.zig
index 6f62b827..4bb60079 100644
--- a/core/term/term.zig
+++ b/core/term/term.zig
@@ -63,8 +63,6 @@ pub const ops: iface.Ops = .{
.spanColor = terminal_.spanColor,
.paint = cast(iface.Ops, "paint", terminal_.paint),
.images = cast(iface.Ops, "images", terminal_.images),
- .petscii = cast(iface.Ops, "petscii", terminal_.petscii),
- .togglePetscii = cast(iface.Ops, "togglePetscii", terminal_.togglePetscii),
.hasImages = cast(iface.Ops, "hasImages", terminal_.hasImages),
.encoder = cast(iface.Ops, "encoder", terminal_.encoder),
.encoderFree = cast(iface.Ops, "encoderFree", terminal_.encoderFree),
diff --git a/core/term/terminal.zig b/core/term/terminal.zig
index a4120f5a..4de389bd 100644
--- a/core/term/terminal.zig
+++ b/core/term/terminal.zig
@@ -181,9 +181,6 @@ pub const State = struct {
reply: [4096]u8 = undefined,
reply_len: u16 = 0,
reply_dropped: u32 = 0,
- /// The grid cell the program last heard the mouse at, so motion is
- /// reported once per cell.
- mouse_cell: ?ghostty_vt.Coordinate = null,
/// The kitty graphics its program placed, as drawn (TerminalImages.zig).
images: TerminalImages = if (images_enabled) .{} else {},
/// Counts the emulator's writes (output, a resize, its view scrolled):
@@ -257,8 +254,6 @@ pub fn parts(s: *const State) Term.Parts {
return .{
.reply = s.reply[0..s.reply_len],
.reply_dropped = s.reply_dropped,
- .mouse_cell = if (s.mouse_cell) |c| .{ .x = c.x, .y = c.y } else null,
- .petscii = if (comptime images_enabled) s.images.petscii else false,
.view = s.vt.screens.active.pages.scrollbar().offset,
.phase = h.phase,
.started = h.started,
@@ -370,8 +365,6 @@ fn install(out: *State, continuation: ghostty_vt.snapshot.Continuation, saved: *
@memcpy(out.reply[0..reply.len], reply);
out.reply_len = @intCast(reply.len);
out.reply_dropped = saved.reply_dropped;
- out.mouse_cell = coordinate(saved.mouse_cell);
- out.images = if (images_enabled) .{ .petscii = saved.petscii } else {};
const h = &out.stream.handler;
h.phase = saved.phase;
h.started = saved.started;
@@ -674,10 +667,13 @@ pub fn paste(state: ?*const State, text: []u8) [3][]const u8 {
/// 1015 urxvt, 1005 UTF-8, else X10) how, modifiers as shift+4, meta+8,
/// 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 mouse(state: *State, buf: *[64]u8, action: Term.MouseAction, button: ?Term.MouseButton, mods: Term.MouseMods, col: i32, row: i32, any_pressed: bool) []const u8 {
+/// changed from `last`, the cell it last heard of (its pane's, which a
+/// rollback puts back). Empty when the program does not hear of it.
+pub fn mouse(state: *State, last: *?Term.Parts.Coordinate, 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 cell = coordinate(last.*);
+ defer last.* = if (cell) |c| .{ .x = c.x, .y = c.y } else null;
var opts: input.MouseEncodeOptions = .{
.event = state.vt.flags.mouse_event,
.format = state.vt.flags.mouse_format,
@@ -687,7 +683,7 @@ pub fn mouse(state: *State, buf: *[64]u8, action: Term.MouseAction, button: ?Ter
.padding = .{},
},
.any_button_pressed = any_pressed,
- .last_cell = &state.mouse_cell,
+ .last_cell = &cell,
};
// A release is always reported; the rest only over the grid, or held.
if (action == .release) opts.any_button_pressed = true;
@@ -716,7 +712,7 @@ pub fn mouse(state: *State, buf: *[64]u8, action: Term.MouseAction, button: ?Ter
/// 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 (`Modes.wheel`).
-pub fn wheel(state: *State, buf: *[64]u8, turn: Term.MouseButton, col: u16, row: u16, mods: Term.MouseMods) ?[]const u8 {
+pub fn wheel(state: *State, last: *?Term.Parts.Coordinate, 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;
@@ -725,7 +721,7 @@ pub fn wheel(state: *State, buf: *[64]u8, turn: Term.MouseButton, col: u16, row:
.wheel_down => if (m.get(.cursor_keys)) "\x1bOB" else "\x1b[B",
else => null,
};
- return mouse(state, buf, .press, turn, mods, col, row, false);
+ return mouse(state, last, buf, .press, turn, mods, col, row, false);
}
/// The whole scrollback as plain text, `gpa`-owned: what a terminal's body
@@ -1536,21 +1532,6 @@ pub fn due(state: *const State) ?u64 {
return state.images.animation_due_ms;
}
-/// The Petscii builtin on a terminal: its kitty graphics as glyph art,
-/// or back to pixels where the shell draws pixels.
-pub fn togglePetscii(state: *State) void {
- if (comptime !images_enabled) return;
- state.images.petscii = !state.images.petscii;
-}
-
-/// Whether the pane draws its kitty graphics as glyph art by choice; null
-/// for a pane with no emulator.
-pub fn petscii(maybe: ?*const State) ?bool {
- if (comptime !images_enabled) return null;
- const state = maybe orelse return null;
- return state.images.petscii;
-}
-
/// Whether the screen showing holds any kitty graphics image.
pub fn hasImages(maybe: ?*const State) bool {
if (comptime !images_enabled) return false;