diff options
Diffstat (limited to 'src/terminal.zig')
| -rw-r--r-- | src/terminal.zig | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/terminal.zig b/src/terminal.zig index 42268f0a..acff68f4 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -2313,7 +2313,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 crossed = true; const upto = anchor.shell_len - @min(anchor.suffix, anchor.shell_len); while (sb < upto) { - const ci = pages.getCell(.{ .viewport = .{ .x = gc, .y = @intCast(vi) } }) orelse break; + const ci = cellAt(pages, row_pin, gc) orelse break; sb += dumpedBytes(row_pin, ci.cell); gc = std.math.add(u16, gc, 1) catch break; } @@ -2324,7 +2324,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 var covered: usize = 0; var style: ?pardes.CellStyle = null; while (covered < want) { - const ci = pages.getCell(.{ .viewport = .{ .x = gc, .y = @intCast(vi) } }) orelse break; + const ci = cellAt(pages, row_pin, gc) orelse break; if (style == null and ci.cell.wide != .spacer_tail and ci.cell.wide != .spacer_head) style = cellStyle(p, ci, filtered, scnm); covered += dumpedBytes(row_pin, ci.cell); @@ -2333,7 +2333,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 // spin on a row that ends in one. if (covered == 0 and gc >= pane.cols) break; } - while (pages.getCell(.{ .viewport = .{ .x = gc, .y = @intCast(vi) } })) |t| { + while (cellAt(pages, row_pin, gc)) |t| { if (t.cell.wide != .spacer_tail) break; gc = std.math.add(u16, gc, 1) catch break; } @@ -2350,7 +2350,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 var tail: ?pardes.CellStyle = null; if (anchor.whole() or anchor.suffix > 0) { while (sc < tw) { - const ci = pages.getCell(.{ .viewport = .{ .x = gc, .y = @intCast(vi) } }) orelse break; + const ci = cellAt(pages, row_pin, gc) orelse break; gc = std.math.add(u16, gc, 1) catch break; if (ci.cell.wide == .spacer_tail) continue; const cell = s.at(tx + sc, body_y + vr); @@ -2371,6 +2371,16 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 } } +/// The cell at column `x` of the row `row` pins, as `pages.getCell` reads +/// it, without walking from the viewport's top down to the row again: that +/// walk, once a cell, was most of a terminal's paint (once getCell was no +/// longer inlined, a frame of a 120x40 shell took 75 µs more). +fn cellAt(pages: *const ghostty_vt.PageList, row: ghostty_vt.Pin, x: u16) ?ghostty_vt.PageList.Cell { + if (x >= pages.cols or x >= row.node.cols()) return null; + const rac = row.node.page().getRowAndCell(x, row.y); + return .{ .node = row.node, .row = rac.row, .cell = rac.cell, .row_idx = row.y, .col_idx = x }; +} + fn cellStyle(p: *Pardes, ci: ghostty_vt.PageList.Cell, filtered: ?*FilteredColors, scnm: bool) pardes.CellStyle { const style = ci.style(); var cs: pardes.CellStyle = .{ |
