mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
reverse colors
This commit is contained in:
@ -561,16 +561,43 @@ fn renderTimerCallback(t: *libuv.Timer) void {
|
||||
|
||||
const win = t.getData(Window).?;
|
||||
|
||||
// Calculate foreground and background colors
|
||||
const fg = win.grid.foreground;
|
||||
defer win.grid.foreground = fg;
|
||||
if (win.terminal.mode_reverse_colors) {
|
||||
win.grid.foreground = .{
|
||||
.r = @floatToInt(u8, win.bg_r * 255),
|
||||
.g = @floatToInt(u8, win.bg_g * 255),
|
||||
.b = @floatToInt(u8, win.bg_b * 255),
|
||||
};
|
||||
}
|
||||
|
||||
// Set our background
|
||||
const bg: struct {
|
||||
r: f32,
|
||||
g: f32,
|
||||
b: f32,
|
||||
a: f32,
|
||||
} = if (win.terminal.mode_reverse_colors) .{
|
||||
.r = @intToFloat(f32, fg.r) / 255,
|
||||
.g = @intToFloat(f32, fg.g) / 255,
|
||||
.b = @intToFloat(f32, fg.b) / 255,
|
||||
.a = 1.0,
|
||||
} else .{
|
||||
.r = win.bg_r,
|
||||
.g = win.bg_g,
|
||||
.b = win.bg_b,
|
||||
.a = win.bg_a,
|
||||
};
|
||||
gl.clearColor(bg.r, bg.g, bg.b, bg.a);
|
||||
gl.clear(gl.c.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Update the cells for drawing
|
||||
win.grid.updateCells(win.terminal) catch unreachable;
|
||||
|
||||
// Update our texture if we have to
|
||||
win.grid.flushAtlas() catch unreachable;
|
||||
|
||||
// Set our background
|
||||
gl.clearColor(win.bg_r, win.bg_g, win.bg_b, win.bg_a);
|
||||
gl.clear(gl.c.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Render the grid
|
||||
win.grid.render() catch |err| {
|
||||
log.err("error rendering grid: {}", .{err});
|
||||
@ -688,6 +715,13 @@ pub fn setTopAndBottomMargin(self: *Window, top: u16, bot: u16) !void {
|
||||
|
||||
pub fn setMode(self: *Window, mode: terminal.Mode, enabled: bool) !void {
|
||||
switch (mode) {
|
||||
.reverse_colors => {
|
||||
self.terminal.mode_reverse_colors = enabled;
|
||||
|
||||
// Schedule a render since we changed colors
|
||||
try self.render_timer.schedule();
|
||||
},
|
||||
|
||||
.origin => {
|
||||
self.terminal.mode_origin = enabled;
|
||||
self.terminal.setCursorPos(1, 1);
|
||||
|
@ -44,6 +44,7 @@ scrolling_region: ScrollingRegion,
|
||||
/// Modes
|
||||
// TODO: turn into a bitset probably
|
||||
mode_origin: bool = false,
|
||||
mode_reverse_colors: bool = false,
|
||||
|
||||
/// Scrolling region is the area of the screen designated where scrolling
|
||||
/// occurs. Wen scrolling the screen, only this viewport is scrolled.
|
||||
|
@ -42,6 +42,9 @@ pub const RenditionAspect = enum(u16) {
|
||||
/// values correspond to the `?`-prefixed modes, since those are the ones
|
||||
/// of primary interest. The enum value is the mode value.
|
||||
pub const Mode = enum(u16) {
|
||||
/// Reverses the foreground and background colors of all cells.
|
||||
reverse_colors = 5,
|
||||
|
||||
/// If set, the origin of the coordinate system is relative to the
|
||||
/// current scroll region. If set the cursor is moved to the top left of
|
||||
/// the current scroll region.
|
||||
|
Reference in New Issue
Block a user