summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md9
-rw-r--r--src/gui/Post.zig2
-rw-r--r--src/terminal.zig135
3 files changed, 139 insertions, 7 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index fc8ede3b..2144f710 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,15 @@
## Unreleased
+- ghostty moves to its 1.4.0 release (from a main commit six days before
+ it; libvaxis and uucode stay on the commits it pins). A terminal's
+ `clear` (ED 3) now takes away the kitty images placed on the history it
+ erases, where they used to come back at the top of the pane; a
+ cancelled kitty command (CAN, SUB) no longer runs; and a command whose
+ output ED 3 erased after it finished reads as not whole, with no text,
+ instead of the rows that took its place. An edited copy or a selection
+ whose top row ED 3 erased now goes, as the copy already did when its
+ rows were pruned, instead of moving to the top.
- Window mode (Ctrl-w, SPC w) takes `d` and `c`: `d` is Del on the
outlined pane, asking k or j between two panes as SPC d does, and the
outline moves to the pane that took the rows; `c` collapses it. The mode
diff --git a/src/gui/Post.zig b/src/gui/Post.zig
index 17e8d7e9..a79d9f0c 100644
--- a/src/gui/Post.zig
+++ b/src/gui/Post.zig
@@ -577,7 +577,7 @@ pub fn deinit(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice) voi
for (post.ping) |texture| if (texture) |t| c.SDL_ReleaseGPUTexture(device, t);
}
-/// ghostty 1.3.2's Uniforms (src/renderer/shadertoy.zig), copied: the offsets
+/// ghostty 1.4.0's Uniforms (src/renderer/shadertoy.zig), copied: the offsets
/// ours must match. Its last two names are swapped against its own GLSL.
const GhosttyUniforms = extern struct {
resolution: [3]f32 align(16),
diff --git a/src/terminal.zig b/src/terminal.zig
index 755fde6c..77ee9b44 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -54,9 +54,11 @@ pub const MarkedHandler = if (enabled) struct {
out_start: ?*ghostty_vt.Pin = null,
out_end: ?*ghostty_vt.Pin = null,
/// The running command's output was erased under it -- a clear, ED 3,
- /// a reset -- so the pins no longer span what it printed: ED 3 moves
- /// a pin to the next page without flagging it `garbage`
- /// (PageList.erasePage).
+ /// a reset -- so the pins no longer span what it printed. ED 3 flags a
+ /// pin on an erased history row `garbage` (ghostty 1.4), but `pinTop`
+ /// re-pins the start at the screen's top, so the flag is gone with the
+ /// old pin: this remembers it, as it does for a reset or a pin that
+ /// could not be made.
lost: bool = false,
/// The newest command to end: which one, and its status if given.
@@ -950,6 +952,11 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void {
}
}
const overlay = groups[0].overlay;
+ // Where the live pane's own selections sit in `positions`: one whose
+ // row the program erased goes (below), as the edited copy does.
+ const vsel_at: ?usize = if (pane.body.vsel.active) 1 else null;
+ const msel_at: ?usize = if (pane.body.msel.active) npositions else null;
+ const sels_at = npositions + @as(usize, if (pane.body.msel.active) 2 else 0);
var extra: [panes.Text.max_selections * 2 + 4]*i32 = undefined;
var nextra: usize = 0;
if (pane.body.msel.active) {
@@ -1018,6 +1025,24 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void {
if (span.end.pin) |pin| owner.untrackPin(pin);
}
}
+ // The rule above for the copy holds for the selections: one whose row
+ // is gone (ED 3 erased its history row, which ghostty flags `garbage`)
+ // goes too, rather than being clamped to the top.
+ const erased = struct {
+ fn at(owner: ?*ghostty_vt.PageList, all: []const PositionPin, index: usize) bool {
+ if (owner == null) return false;
+ const pin = all[index].row.pin orelse return false;
+ return pin.garbage;
+ }
+ }.at;
+ const vsel_lost = if (vsel_at) |i|
+ erased(alive, positions[0..npositions], i) or (copy_lost and positions[i].edit_row != null)
+ else
+ false;
+ const msel_lost = if (msel_at) |i| erased(alive, positions[0..npositions], i) or erased(alive, positions[0..npositions], i + 1) else false;
+ var sels_keep: [panes.Text.max_selections]bool = undefined;
+ for (0..pane.body.nsel) |i| sels_keep[i] = !(erased(alive, positions[0..npositions], sels_at + 2 * i) or
+ erased(alive, positions[0..npositions], sels_at + 2 * i + 1));
for ([_][]PositionPin{ positions[0..npositions], pointer_positions orelse &.{} }) |batch| for (batch) |position| {
var row = pinnedRow(alive, position.row);
if (position.overlay) |edit| {
@@ -1038,6 +1063,25 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void {
pane.clearPointerSelection(button);
pane.sel[button].state = .none;
};
+ if (vsel_lost) {
+ pane.body.vsel.active = false;
+ moved = true;
+ }
+ if (msel_lost) {
+ pane.body.msel.active = false;
+ moved = true;
+ }
+ if (pane.body.nsel > 0) {
+ var kept: u16 = 0;
+ for (0..pane.body.nsel) |i| if (sels_keep[i]) {
+ pane.body.sels[kept] = pane.body.sels[i];
+ kept += 1;
+ };
+ if (kept != pane.body.nsel) {
+ moved = true;
+ if (kept == 0) pane.body.dropSels() else pane.body.nsel = kept;
+ }
+ }
if (copy_lost) if (pane.ovl) |copy| {
pane.gpa.free(copy.text);
pane.ovl = null;
@@ -1110,9 +1154,10 @@ pub const CommandOutput = struct {
text: [:0]const u8,
/// Whether `text` starts where the command did. It does not when that
/// start is not there to read: cut off by `max_rows`, scrolled out of
- /// the history (ghostty moved the pin to the oldest row it kept and
- /// flagged it `garbage`), erased under it (`MarkedHandler.lost`), or
- /// never pinned (a C or D that came on the alternate screen).
+ /// the history or erased from it by ED 3 (ghostty flags the pin
+ /// `garbage`; an erased end leaves no text at all), erased under it
+ /// while it ran (`MarkedHandler.lost`), or never pinned (a C or D that
+ /// came on the alternate screen).
whole: bool,
};
@@ -2979,6 +3024,84 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
}
+/// `n` line breaks: enough of them push the screen's rows into history.
+fn lineBreaks(comptime n: usize) [2 * n]u8 {
+ var out: [2 * n]u8 = undefined;
+ for (0..n) |i| out[2 * i ..][0..2].* = "\r\n".*;
+ return out;
+}
+
+test "ED 3 takes away a kitty placement whose row it erased: it never comes back at the top" {
+ if (comptime !images_enabled) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 });
+ defer p.deinit();
+ p.native_images = true;
+ p.update(.{ .resize = .{ .cols = 80, .rows = 24, .cell_pixels = .{ .w = 10, .h = 20 } } });
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ const pane = p.panes[0].?;
+ pane.body.mode = .tty;
+ p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[1;1H" ++ kittyTransmit("c=2,r=1") } });
+ const storage = &pane.terminal.?.vt.screens.active.kitty_images;
+ try std.testing.expectEqual(@as(usize, 1), storage.placements.count());
+ // Scrolled into the history, it is not on screen; `clear` (ED 2 then
+ // ED 3) erases that history and the placement with it.
+ p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(40) } });
+ var s = try p.render(frame.allocator());
+ try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
+ p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[H\x1b[2J\x1b[3J" } });
+ try std.testing.expectEqual(@as(usize, 0), storage.placements.count());
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len);
+}
+
+test "a finished command's output erased by a later ED 3 is not called whole, and no rows stand in for it" {
+ if (comptime !enabled) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 6 });
+ defer p.deinit();
+ const pane = p.panes[0].?;
+ const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
+ p.update(.{ .output = .{ .pane = 0, .bytes = prompt ++ "\r\n\x1b]133;C;aid=pardes\x07printed\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt } });
+ const before = try commandOutput(pane, gpa, 100);
+ defer gpa.free(before.text);
+ try std.testing.expect(before.whole);
+ try std.testing.expect(std.mem.startsWith(u8, before.text, "printed"));
+ // The command's rows go into the history, and ED 3 erases them: its
+ // pins are `garbage` now (ghostty 1.4), not moved to the screen's top,
+ // where another program's text would be read as its output.
+ p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(20) } });
+ p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } });
+ const after = try commandOutput(pane, gpa, 100);
+ defer gpa.free(after.text);
+ try std.testing.expect(!after.whole);
+ try std.testing.expectEqualStrings("", after.text);
+}
+
+test "a selection whose row ED 3 erased goes; one on the screen stays" {
+ if (comptime !enabled) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ for ([_]bool{ true, false }) |in_history| {
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 6 });
+ defer p.deinit();
+ const pane = p.panes[0].?;
+ pane.body.mode = .tty;
+ p.update(.{ .output = .{ .pane = 0, .bytes = &lineBreaks(20) } });
+ pane.body.mode = .normal;
+ const pages = &pane.terminal.?.vt.screens.active.pages;
+ const top: i32 = @intCast(pages.total_rows - pane.rows);
+ const row: i32 = if (in_history) top - 3 else top + 2;
+ pane.body.vsel = .{ .active = true, .row = row, .col = 1 };
+ pane.body.msel = .{ .active = true, .r0 = row, .r1 = row };
+ p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J" } });
+ try std.testing.expectEqual(!in_history, pane.body.vsel.active);
+ try std.testing.expectEqual(!in_history, pane.body.msel.active);
+ if (!in_history) try std.testing.expectEqual(@as(i32, 2), pane.body.vsel.row);
+ }
+}
+
test "a virtual kitty placement shows through its placeholder cells, which draw no text" {
if (comptime !images_enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;