mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
invert attribute
This commit is contained in:
46
src/Grid.zig
46
src/Grid.zig
@ -45,6 +45,9 @@ cursor_style: CursorStyle,
|
|||||||
/// Default foreground color
|
/// Default foreground color
|
||||||
foreground: terminal.color.RGB,
|
foreground: terminal.color.RGB,
|
||||||
|
|
||||||
|
/// Default background color
|
||||||
|
background: terminal.color.RGB,
|
||||||
|
|
||||||
/// Available cursor styles for drawing. The values represents the mode value
|
/// Available cursor styles for drawing. The values represents the mode value
|
||||||
/// in the shader.
|
/// in the shader.
|
||||||
pub const CursorStyle = enum(u8) {
|
pub const CursorStyle = enum(u8) {
|
||||||
@ -242,6 +245,7 @@ pub fn init(alloc: Allocator) !Grid {
|
|||||||
.atlas_dirty = false,
|
.atlas_dirty = false,
|
||||||
.cursor_visible = true,
|
.cursor_visible = true,
|
||||||
.cursor_style = .box,
|
.cursor_style = .box,
|
||||||
|
.background = .{ .r = 0, .g = 0, .b = 0 },
|
||||||
.foreground = .{ .r = 255, .g = 255, .b = 255 },
|
.foreground = .{ .r = 255, .g = 255, .b = 255 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -283,10 +287,34 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
defer y += 1;
|
defer y += 1;
|
||||||
|
|
||||||
for (line) |cell, x| {
|
for (line) |cell, x| {
|
||||||
// TODO: inverse
|
// The colors for the cell.
|
||||||
|
const colors: struct {
|
||||||
|
/// Background is optional because in un-inverted mode
|
||||||
|
/// it may just be equivalent to the default background in
|
||||||
|
/// which case we do nothing to save on GPU render time.
|
||||||
|
bg: ?terminal.color.RGB,
|
||||||
|
|
||||||
|
/// Fg is always set to some color, though we may not render
|
||||||
|
/// any fg if the cell is empty or has no attributes like
|
||||||
|
/// underline.
|
||||||
|
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.
|
||||||
|
.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.
|
||||||
|
//
|
||||||
|
// TODO(mitchellh): How should this interact with DECSCNM?
|
||||||
|
.bg = cell.fg orelse self.foreground,
|
||||||
|
.fg = cell.bg orelse self.background,
|
||||||
|
};
|
||||||
|
|
||||||
// If the cell has a background, we always draw it.
|
// If the cell has a background, we always draw it.
|
||||||
if (cell.bg) |rgb| {
|
if (colors.bg) |rgb| {
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = 1,
|
.mode = 1,
|
||||||
.grid_col = @intCast(u16, x),
|
.grid_col = @intCast(u16, x),
|
||||||
@ -308,8 +336,6 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fg = cell.fg orelse self.foreground;
|
|
||||||
|
|
||||||
// If the cell is empty then we draw nothing in the box.
|
// If the cell is empty then we draw nothing in the box.
|
||||||
if (!cell.empty()) {
|
if (!cell.empty()) {
|
||||||
// Determine our glyph styling
|
// Determine our glyph styling
|
||||||
@ -337,9 +363,9 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
.glyph_height = glyph.height,
|
.glyph_height = glyph.height,
|
||||||
.glyph_offset_x = glyph.offset_x,
|
.glyph_offset_x = glyph.offset_x,
|
||||||
.glyph_offset_y = glyph.offset_y,
|
.glyph_offset_y = glyph.offset_y,
|
||||||
.fg_r = fg.r,
|
.fg_r = colors.fg.r,
|
||||||
.fg_g = fg.g,
|
.fg_g = colors.fg.g,
|
||||||
.fg_b = fg.b,
|
.fg_b = colors.fg.b,
|
||||||
.fg_a = 255,
|
.fg_a = 255,
|
||||||
.bg_r = 0,
|
.bg_r = 0,
|
||||||
.bg_g = 0,
|
.bg_g = 0,
|
||||||
@ -359,9 +385,9 @@ pub fn updateCells(self: *Grid, term: Terminal) !void {
|
|||||||
.glyph_height = 0,
|
.glyph_height = 0,
|
||||||
.glyph_offset_x = 0,
|
.glyph_offset_x = 0,
|
||||||
.glyph_offset_y = 0,
|
.glyph_offset_y = 0,
|
||||||
.fg_r = fg.r,
|
.fg_r = colors.fg.r,
|
||||||
.fg_g = fg.g,
|
.fg_g = colors.fg.g,
|
||||||
.fg_b = fg.b,
|
.fg_b = colors.fg.b,
|
||||||
.fg_a = 255,
|
.fg_a = 255,
|
||||||
.bg_r = 0,
|
.bg_r = 0,
|
||||||
.bg_g = 0,
|
.bg_g = 0,
|
||||||
|
@ -150,6 +150,11 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
|
|||||||
const window_size = try window.getSize();
|
const window_size = try window.getSize();
|
||||||
var grid = try Grid.init(alloc);
|
var grid = try Grid.init(alloc);
|
||||||
try grid.setScreenSize(.{ .width = window_size.width, .height = window_size.height });
|
try grid.setScreenSize(.{ .width = window_size.width, .height = window_size.height });
|
||||||
|
grid.background = .{
|
||||||
|
.r = config.background.r,
|
||||||
|
.g = config.background.g,
|
||||||
|
.b = config.background.b,
|
||||||
|
};
|
||||||
grid.foreground = .{
|
grid.foreground = .{
|
||||||
.r = config.foreground.r,
|
.r = config.foreground.r,
|
||||||
.g = config.foreground.g,
|
.g = config.foreground.g,
|
||||||
|
Reference in New Issue
Block a user