summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/terminal.zig b/src/terminal.zig
index 3190c6e3..a8e7931c 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -207,7 +207,7 @@ const LivePalette = struct {
var seed = GColor.default;
for (base, 0..) |rgb, i| seed[i] = rgb;
- self.colors = GColor.generate256Color(seed, .initEmpty(), bg, fg, false);
+ self.colors = GColor.generate256Color(seed, .empty, bg, fg, false);
self.key = key;
return &self.colors;
}
@@ -609,10 +609,10 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
state.vt = try ghostty_vt.Terminal.init(terminalIo(), gpa, .{
.cols = cols,
.rows = rows,
- .max_scrollback = 16 * 1024 * 1024,
+ .max_scrollback_bytes = 16 * 1024 * 1024,
.kitty_image_storage_limit = if (images_enabled) TerminalImages.storage_limit else 0,
});
- state.stream = .initAlloc(gpa, .{ .inner = state.vt.vtHandler() });
+ state.stream = .init(.{ .handler = .{ .inner = state.vt.vtHandler() }, .allocator = gpa });
state.replay.head = 0;
state.replay.len = 0;
state.reply_len = 0;
@@ -1055,7 +1055,11 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void {
}
};
} else failed = true;
+ // Whether the program cleared the screen (ED 2, a switch of screens);
+ // pardes reads the flag nowhere else.
+ pane.terminal.?.vt.flags.dirty.clear = false;
ingest(pane, bytes);
+ const cleared = pane.terminal.?.vt.flags.dirty.clear;
// RIS can destroy the alternate screen and every pin it owned.
const alive = if (screens.generation(key) == generation) pages else null;
var moved = false;
@@ -1065,7 +1069,15 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void {
if (pin.garbage) pointer_rows_lost = true;
};
};
+ // The program cleared the screen, or the rows the live copy stood on are
+ // gone (pruned, a reset): the copy goes with them, as what the program
+ // drew next. Kept, ghostty would move its rows to the top of what is
+ // left, over the program's new text.
+ var copy_lost = cleared or alive == null;
for (spans[0..nspans]) |span| {
+ if (span.overlay == overlay) if (span.start.pin) |pin| if (alive != null and pin.garbage) {
+ copy_lost = true;
+ };
const start = pinnedRow(alive, span.start);
const rows = @max(1, pinnedRow(alive, span.end) -| start +| 1);
moved = moved or start != span.overlay.row or rows != span.overlay.rows;
@@ -1096,6 +1108,11 @@ fn ingestWithPositions(pane: *Pane, bytes: []const u8) void {
pane.clearPointerSelection(button);
pane.sel[button].state = .none;
};
+ if (copy_lost) if (pane.ovl) |copy| {
+ pane.gpa.free(copy.text);
+ pane.ovl = null;
+ moved = true;
+ };
if (moved) pane.nsel_snap = 0; // Saved regex-preview offsets name the old flat text.
if (failed) {
const message = "terminal edit position reset: out of memory";
@@ -1211,7 +1228,7 @@ pub fn commandOutput(pane: *Pane, gpa: std.mem.Allocator, max_rows: usize) !Comm
.whole = whole,
};
} else true;
- return .{ .text = try gpa.dupeZ(u8, ""), .whole = whole };
+ return .{ .text = try gpa.dupeSentinel(u8, "", 0), .whole = whole };
}
/// At a prompt with nothing typed on its line: no input left of the
@@ -2813,7 +2830,7 @@ pub fn redo(p: *Pardes, pane: *Pane) void {
pane.ensureCursorVisible();
}
-pub fn ptyReport(handler: *ghostty_vt.TerminalStream.Handler, data: [:0]const u8) void {
+pub fn ptyReport(handler: *ghostty_vt.TerminalStream.Handler, data: []const u8) void {
const state: *State = @alignCast(@fieldParentPtr("vt", handler.terminal));
const room = state.reply.len - state.reply_len;
const n = @min(room, data.len);
@@ -2968,7 +2985,8 @@ test "a program that asked for focus reports hears CSI I and CSI O as its pane t
/// over two cells).
inline fn kittyTransmit(comptime extra: []const u8) []const u8 {
return comptime blk: {
- const pixels = [_]u8{ 255, 0, 0, 255, 0, 0, 0, 0, 255, 0, 0, 255 } ** 2;
+ const row = [_]u8{ 255, 0, 0, 255, 0, 0, 0, 0, 255, 0, 0, 255 };
+ const pixels = row ++ row;
var buf: [std.base64.standard.Encoder.calcSize(pixels.len)]u8 = undefined;
const b64 = std.base64.standard.Encoder.encode(&buf, &pixels)[0..buf.len].*;
break :blk "\x1b_Ga=T,f=24,s=4,v=2,i=7," ++ extra ++ ";" ++ b64 ++ "\x1b\\";