mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
renderer: support invisible attribute
This commit is contained in:
@ -935,22 +935,26 @@ pub fn updateCell(
|
|||||||
// cell is selected.
|
// cell is selected.
|
||||||
// TODO(perf): we can check in advance if selection is in
|
// TODO(perf): we can check in advance if selection is in
|
||||||
// our viewport at all and not run this on every point.
|
// our viewport at all and not run this on every point.
|
||||||
if (selection) |sel| {
|
var selection_res: ?BgFg = sel_colors: {
|
||||||
const screen_point = (terminal.point.Viewport{
|
if (selection) |sel| {
|
||||||
.x = x,
|
const screen_point = (terminal.point.Viewport{
|
||||||
.y = y,
|
.x = x,
|
||||||
}).toScreen(screen);
|
.y = y,
|
||||||
|
}).toScreen(screen);
|
||||||
|
|
||||||
// If we are selected, we our colors are just inverted fg/bg
|
// If we are selected, we our colors are just inverted fg/bg
|
||||||
if (sel.contains(screen_point)) {
|
if (sel.contains(screen_point)) {
|
||||||
break :colors BgFg{
|
break :sel_colors BgFg{
|
||||||
.bg = self.config.selection_background orelse self.config.foreground,
|
.bg = self.config.selection_background orelse self.config.foreground,
|
||||||
.fg = self.config.selection_foreground orelse self.config.background,
|
.fg = self.config.selection_foreground orelse self.config.background,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const res: BgFg = if (!cell.attrs.inverse) .{
|
break :sel_colors null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const res: BgFg = selection_res orelse if (!cell.attrs.inverse) .{
|
||||||
// In normal mode, background and fg match the cell. We
|
// In normal mode, background and fg match the cell. We
|
||||||
// un-optionalize the fg by defaulting to our fg color.
|
// un-optionalize the fg by defaulting to our fg color.
|
||||||
.bg = if (cell.attrs.has_bg) cell.bg else null,
|
.bg = if (cell.attrs.has_bg) cell.bg else null,
|
||||||
@ -962,6 +966,16 @@ pub fn updateCell(
|
|||||||
.bg = if (cell.attrs.has_fg) cell.fg else self.config.foreground,
|
.bg = if (cell.attrs.has_fg) cell.fg else self.config.foreground,
|
||||||
.fg = if (cell.attrs.has_bg) cell.bg else self.config.background,
|
.fg = if (cell.attrs.has_bg) cell.bg else self.config.background,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If the cell is "invisible" then we just make fg = bg so that
|
||||||
|
// the cell is transparent but still copy-able.
|
||||||
|
if (cell.attrs.invisible) {
|
||||||
|
break :colors BgFg{
|
||||||
|
.bg = res.bg,
|
||||||
|
.fg = res.bg orelse self.config.background,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
break :colors res;
|
break :colors res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1056,22 +1056,26 @@ pub fn updateCell(
|
|||||||
// cell is selected.
|
// cell is selected.
|
||||||
// TODO(perf): we can check in advance if selection is in
|
// TODO(perf): we can check in advance if selection is in
|
||||||
// our viewport at all and not run this on every point.
|
// our viewport at all and not run this on every point.
|
||||||
if (selection) |sel| {
|
var selection_res: ?BgFg = sel_colors: {
|
||||||
const screen_point = (terminal.point.Viewport{
|
if (selection) |sel| {
|
||||||
.x = x,
|
const screen_point = (terminal.point.Viewport{
|
||||||
.y = y,
|
.x = x,
|
||||||
}).toScreen(screen);
|
.y = y,
|
||||||
|
}).toScreen(screen);
|
||||||
|
|
||||||
// If we are selected, we use the selection colors
|
// If we are selected, we our colors are just inverted fg/bg
|
||||||
if (sel.contains(screen_point)) {
|
if (sel.contains(screen_point)) {
|
||||||
break :colors BgFg{
|
break :sel_colors BgFg{
|
||||||
.bg = self.config.selection_background orelse self.config.foreground,
|
.bg = self.config.selection_background orelse self.config.foreground,
|
||||||
.fg = self.config.selection_foreground orelse self.config.background,
|
.fg = self.config.selection_foreground orelse self.config.background,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const res: BgFg = if (!cell.attrs.inverse) .{
|
break :sel_colors null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const res: BgFg = selection_res orelse if (!cell.attrs.inverse) .{
|
||||||
// In normal mode, background and fg match the cell. We
|
// In normal mode, background and fg match the cell. We
|
||||||
// un-optionalize the fg by defaulting to our fg color.
|
// un-optionalize the fg by defaulting to our fg color.
|
||||||
.bg = if (cell.attrs.has_bg) cell.bg else null,
|
.bg = if (cell.attrs.has_bg) cell.bg else null,
|
||||||
@ -1083,6 +1087,16 @@ pub fn updateCell(
|
|||||||
.bg = if (cell.attrs.has_fg) cell.fg else self.config.foreground,
|
.bg = if (cell.attrs.has_fg) cell.fg else self.config.foreground,
|
||||||
.fg = if (cell.attrs.has_bg) cell.bg else self.config.background,
|
.fg = if (cell.attrs.has_bg) cell.bg else self.config.background,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If the cell is "invisible" then we just make fg = bg so that
|
||||||
|
// the cell is transparent but still copy-able.
|
||||||
|
if (cell.attrs.invisible) {
|
||||||
|
break :colors BgFg{
|
||||||
|
.bg = res.bg,
|
||||||
|
.fg = res.bg orelse self.config.background,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
break :colors res;
|
break :colors res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -198,6 +198,7 @@ pub const Cell = struct {
|
|||||||
faint: bool = false,
|
faint: bool = false,
|
||||||
blink: bool = false,
|
blink: bool = false,
|
||||||
inverse: bool = false,
|
inverse: bool = false,
|
||||||
|
invisible: bool = false,
|
||||||
strikethrough: bool = false,
|
strikethrough: bool = false,
|
||||||
underline: sgr.Attribute.Underline = .none,
|
underline: sgr.Attribute.Underline = .none,
|
||||||
underline_color: bool = false,
|
underline_color: bool = false,
|
||||||
@ -272,7 +273,7 @@ pub const Cell = struct {
|
|||||||
|
|
||||||
test {
|
test {
|
||||||
//log.warn("CELL={} bits={} {}", .{ @sizeOf(Cell), @bitSizeOf(Cell), @alignOf(Cell) });
|
//log.warn("CELL={} bits={} {}", .{ @sizeOf(Cell), @bitSizeOf(Cell), @alignOf(Cell) });
|
||||||
try std.testing.expectEqual(16, @sizeOf(Cell));
|
try std.testing.expectEqual(20, @sizeOf(Cell));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -491,6 +491,14 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
|
|||||||
self.screen.cursor.pen.attrs.inverse = false;
|
self.screen.cursor.pen.attrs.inverse = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.invisible => {
|
||||||
|
self.screen.cursor.pen.attrs.invisible = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
.reset_invisible => {
|
||||||
|
self.screen.cursor.pen.attrs.invisible = false;
|
||||||
|
},
|
||||||
|
|
||||||
.strikethrough => {
|
.strikethrough => {
|
||||||
self.screen.cursor.pen.attrs.strikethrough = true;
|
self.screen.cursor.pen.attrs.strikethrough = true;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user