mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
color selection!
This commit is contained in:
50
src/Grid.zig
50
src/Grid.zig
@ -288,8 +288,7 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
defer y += 1;
|
defer y += 1;
|
||||||
|
|
||||||
for (line) |cell, x| {
|
for (line) |cell, x| {
|
||||||
// The colors for the cell.
|
const BgFg = struct {
|
||||||
const colors: struct {
|
|
||||||
/// Background is optional because in un-inverted mode
|
/// Background is optional because in un-inverted mode
|
||||||
/// it may just be equivalent to the default background in
|
/// it may just be equivalent to the default background in
|
||||||
/// which case we do nothing to save on GPU render time.
|
/// which case we do nothing to save on GPU render time.
|
||||||
@ -299,17 +298,42 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
/// any fg if the cell is empty or has no attributes like
|
/// any fg if the cell is empty or has no attributes like
|
||||||
/// underline.
|
/// underline.
|
||||||
fg: terminal.color.RGB,
|
fg: terminal.color.RGB,
|
||||||
} = if (cell.attrs.inverse == 0) .{
|
};
|
||||||
// In normal mode, background and fg match the cell. We
|
|
||||||
// un-optionalize the fg by defaulting to our fg color.
|
// The colors for the cell.
|
||||||
.bg = cell.bg,
|
const colors: BgFg = colors: {
|
||||||
.fg = cell.fg orelse self.foreground,
|
// If we have a selection, then we need to check if this
|
||||||
} else .{
|
// cell is selected.
|
||||||
// In inverted mode, the background MUST be set to something
|
// TODO(perf): we can check in advance if selection is in
|
||||||
// (is never null) so it is either the fg or default fg. The
|
// our viewport at all and not run this on every point.
|
||||||
// fg is either the bg or default background.
|
if (term.selection) |sel| {
|
||||||
.bg = cell.fg orelse self.foreground,
|
const screen_point = (terminal.point.Viewport{
|
||||||
.fg = cell.bg orelse self.background,
|
.x = x,
|
||||||
|
.y = y,
|
||||||
|
}).toScreen(&term.screen);
|
||||||
|
|
||||||
|
// If we are selected, we our colors are just inverted fg/bg
|
||||||
|
if (sel.contains(screen_point)) {
|
||||||
|
break :colors BgFg{
|
||||||
|
.bg = self.foreground,
|
||||||
|
.fg = self.background,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const res: BgFg = if (cell.attrs.inverse == 0) .{
|
||||||
|
// In normal mode, background and fg match the cell. We
|
||||||
|
// un-optionalize the fg by defaulting to our fg color.
|
||||||
|
.bg = cell.bg,
|
||||||
|
.fg = cell.fg orelse self.foreground,
|
||||||
|
} else .{
|
||||||
|
// In inverted mode, the background MUST be set to something
|
||||||
|
// (is never null) so it is either the fg or default fg. The
|
||||||
|
// fg is either the bg or default background.
|
||||||
|
.bg = cell.fg orelse self.foreground,
|
||||||
|
.fg = cell.bg orelse self.background,
|
||||||
|
};
|
||||||
|
break :colors res;
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the cell has a background, we always draw it.
|
// If the cell has a background, we always draw it.
|
||||||
|
Reference in New Issue
Block a user