mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
terminal/kitty: calculate cell height more efficiently
This commit is contained in:
@ -222,19 +222,16 @@ fn display(
|
||||
switch (d.cursor_movement) {
|
||||
.none => {},
|
||||
.after => {
|
||||
const rect = p.rect(img, terminal);
|
||||
|
||||
// We can do better by doing this with pure internal screen state
|
||||
// but this handles scroll regions.
|
||||
const height = rect.bottom_right.y - rect.top_left.y;
|
||||
for (0..height) |_| terminal.index() catch |err| {
|
||||
// We use terminal.index to properly handle scroll regions.
|
||||
const size = p.gridSize(img, terminal);
|
||||
for (0..size.rows) |_| terminal.index() catch |err| {
|
||||
log.warn("failed to move cursor: {}", .{err});
|
||||
break;
|
||||
};
|
||||
|
||||
terminal.setCursorPos(
|
||||
terminal.screen.cursor.y,
|
||||
rect.bottom_right.x + 1,
|
||||
p.pin.x + size.cols + 1,
|
||||
);
|
||||
},
|
||||
}
|
||||
|
@ -581,23 +581,19 @@ pub const ImageStorage = struct {
|
||||
s.pages.untrackPin(self.pin);
|
||||
}
|
||||
|
||||
/// Returns a selection of the entire rectangle this placement
|
||||
/// occupies within the screen.
|
||||
pub fn rect(
|
||||
/// Returns the size in grid cells that this placement takes up.
|
||||
pub fn gridSize(
|
||||
self: Placement,
|
||||
image: Image,
|
||||
t: *const terminal.Terminal,
|
||||
) Rect {
|
||||
// If we have columns/rows specified we can simplify this whole thing.
|
||||
if (self.columns > 0 and self.rows > 0) {
|
||||
var br = switch (self.pin.downOverflow(self.rows)) {
|
||||
.offset => |v| v,
|
||||
.overflow => |v| v.end,
|
||||
) struct {
|
||||
cols: u32,
|
||||
rows: u32,
|
||||
} {
|
||||
if (self.columns > 0 and self.rows > 0) return .{
|
||||
.cols = self.columns,
|
||||
.rows = self.rows,
|
||||
};
|
||||
br.x = @min(self.pin.x + self.columns, t.cols - 1);
|
||||
|
||||
return .{ .top_left = self.pin.*, .bottom_right = br };
|
||||
}
|
||||
|
||||
// Calculate our cell size.
|
||||
const terminal_width_f64: f64 = @floatFromInt(t.width_px);
|
||||
@ -617,12 +613,26 @@ pub const ImageStorage = struct {
|
||||
const width_cells: u32 = @intFromFloat(@ceil(width_f64 / cell_width_f64));
|
||||
const height_cells: u32 = @intFromFloat(@ceil(height_f64 / cell_height_f64));
|
||||
|
||||
// TODO(paged-terminal): clean this logic up above
|
||||
var br = switch (self.pin.downOverflow(height_cells)) {
|
||||
return .{
|
||||
.cols = width_cells,
|
||||
.rows = height_cells,
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns a selection of the entire rectangle this placement
|
||||
/// occupies within the screen.
|
||||
pub fn rect(
|
||||
self: Placement,
|
||||
image: Image,
|
||||
t: *const terminal.Terminal,
|
||||
) Rect {
|
||||
const grid_size = self.gridSize(image, t);
|
||||
|
||||
var br = switch (self.pin.downOverflow(grid_size.rows)) {
|
||||
.offset => |v| v,
|
||||
.overflow => |v| v.end,
|
||||
};
|
||||
br.x = @min(self.pin.x + width_cells, t.cols - 1);
|
||||
br.x = @min(self.pin.x + grid_size.cols, t.cols - 1);
|
||||
|
||||
return .{
|
||||
.top_left = self.pin.*,
|
||||
|
Reference in New Issue
Block a user