Skip to content

Commit

Permalink
Updated docstrings, cleaned up awkward formatting, and moved style co…
Browse files Browse the repository at this point in the history
…mputation to avoid unnecssary invocations
  • Loading branch information
dal-liu committed Jan 22, 2025
1 parent 0c05ff5 commit 6444db4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
29 changes: 20 additions & 9 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,10 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
/// The foreground and background color for selection. If this is not set, then
/// the selection color is just the inverted window background and foreground
/// (note: not to be confused with the cell bg/fg).
/// Specified as either hex (`#RRGGBB` or `RRGGBB`), a named X11 color,
/// `cell-foreground` to match the cell foreground color, or `cell-background`
/// to match the cell background color.
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
/// Since version 1.0.2, this can also be set to `cell-foreground` to match
/// the cell foreground color, or `cell-background` to match the cell
/// background color.
@"selection-foreground": ?DynamicColor = null,
@"selection-background": ?DynamicColor = null,

Expand All @@ -465,6 +466,10 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
///
/// If you select across cells with differing foregrounds and backgrounds, the
/// selection color will vary across the selection.
///
/// Warning: This option has been deprecated as of version 1.0.2. Instead,
/// users should set `selection-foreground` and `selection-background` to
/// `cell-background` and `cell-foreground`, respectively.
@"selection-invert-fg-bg": bool = false,

/// The minimum contrast ratio between the foreground and background colors.
Expand Down Expand Up @@ -494,13 +499,18 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
palette: Palette = .{},

/// The color of the cursor. If this is not set, a default will be chosen.
/// Specified as either hex (`#RRGGBB` or `RRGGBB`), a named X11 color,
/// `cell-foreground` to match the cell foreground color, or `cell-background`
/// to match the cell background color.
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
/// Since version 1.0.2, this can also be set to `cell-foreground` to match
/// the cell foreground color, or `cell-background` to match the cell
/// background color.
@"cursor-color": ?DynamicColor = null,

/// Swap the foreground and background colors of the cell under the cursor. This
/// option overrides the `cursor-color` and `cursor-text` options.
///
/// Warning: This option has been deprecated as of version 1.0.2. Instead,
/// users should set `cursor-color` and `cursor-text` to `cell-foreground` and
/// `cell-background`, respectively.
@"cursor-invert-fg-bg": bool = false,

/// The opacity level (opposite of transparency) of the cursor. A value of 1
Expand Down Expand Up @@ -550,9 +560,10 @@ palette: Palette = .{},

/// The color of the text under the cursor. If this is not set, a default will
/// be chosen.
/// Specified as either hex (`#RRGGBB` or `RRGGBB`), a named X11 color,
/// `cell-foreground` to match the cell foreground color, or `cell-background`
/// to match the cell background color.
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
/// Since version 1.0.2, this can also be set to `cell-foreground` to match
/// the cell foreground color, or `cell-background` to match the cell
/// background color.
@"cursor-text": ?DynamicColor = null,

/// Enables the ability to move the cursor at prompts by using `alt+click` on
Expand Down
32 changes: 20 additions & 12 deletions src/renderer/Metal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2804,20 +2804,24 @@ fn rebuildCells(
// Prepare the cursor cell contents.
const style = cursor_style_ orelse break :cursor;
const cursor_color = self.cursor_color orelse if (self.default_cursor_color) |color| color: {
// If cursor-color is set, then compute the correct color.
// Otherwise, use the foreground color
if (color == .color) {
// Use the color set by cursor-color, if any.
break :color color.color.toTerminalRGB();
}

const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
const fg_style = sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color;
const bg_style = sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color;

break :color switch (color) {
// Use the color set by cursor-color, if any. If the cell
// is reversed, use the opposite cell color instead.
.color => color.color.toTerminalRGB(),
// If the cell is reversed, use the opposite cell color instead.
.@"cell-foreground" => if (sty.flags.inverse) bg_style else fg_style,
.@"cell-background" => if (sty.flags.inverse) fg_style else bg_style,
else => unreachable,
};
} else
// Otherwise, use the foreground color.
self.foreground_color orelse self.default_foreground_color;
} else self.foreground_color orelse self.default_foreground_color;

self.addCursor(screen, style, cursor_color);

Expand All @@ -2842,20 +2846,24 @@ fn rebuildCells(
};

const uniform_color = if (self.config.cursor_text) |txt| blk: {
// If cursor-text is set, then compute the correct color.
// Otherwise, use the background color.
if (txt == .color) {
// Use the color set by cursor-text, if any.
break :blk txt.color.toTerminalRGB();
}

const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
const fg_style = sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color;
const bg_style = sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color;

break :blk switch (txt) {
// Use the color set by cursor-text, if any. If the cell
// is reversed, use the opposite cell color instead.
.color => txt.color.toTerminalRGB(),
// If the cell is reversed, use the opposite cell color instead.
.@"cell-foreground" => if (sty.flags.inverse) bg_style else fg_style,
.@"cell-background" => if (sty.flags.inverse) fg_style else bg_style,
else => unreachable,
};
} else
// Otherwise, use the background color.
self.background_color orelse self.default_background_color;
} else self.background_color orelse self.default_background_color;

self.uniforms.cursor_color = .{
uniform_color.r,
Expand Down
32 changes: 20 additions & 12 deletions src/renderer/OpenGL.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1707,39 +1707,47 @@ pub fn rebuildCells(
}

const cursor_color = self.cursor_color orelse if (self.default_cursor_color) |color| color: {
// If cursor-color is set, then compute the correct color.
// Otherwise, use the foreground color
if (color == .color) {
// Use the color set by cursor-color, if any.
break :color color.color.toTerminalRGB();
}

const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
const fg_style = sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color;
const bg_style = sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color;

break :color switch (color) {
// Use the color set by cursor-color, if any. If the cell
// is reversed, use the opposite cell color instead.
.color => color.color.toTerminalRGB(),
// If the cell is reversed, use the opposite cell color instead.
.@"cell-foreground" => if (sty.flags.inverse) bg_style else fg_style,
.@"cell-background" => if (sty.flags.inverse) fg_style else bg_style,
else => unreachable,
};
} else
// Otherwise, use the foreground color.
self.foreground_color orelse self.default_foreground_color;
} else self.foreground_color orelse self.default_foreground_color;

_ = try self.addCursor(screen, cursor_style, cursor_color);
for (cursor_cells.items) |*cell| {
if (cell.mode.isFg() and cell.mode != .fg_color) {
const cell_color = if (self.config.cursor_text) |txt| blk: {
// If cursor-text is set, then compute the correct color.
// Otherwise, use the background color
if (txt == .color) {
// Use the color set by cursor-text, if any.
break :blk txt.color.toTerminalRGB();
}

const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
const fg_style = sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color;
const bg_style = sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color;

break :blk switch (txt) {
// Use the color set by cursor-text, if any. If the cell
// is reversed, use the opposite cell color instead.
.color => txt.color.toTerminalRGB(),
// If the cell is reversed, use the opposite cell color instead.
.@"cell-foreground" => if (sty.flags.inverse) bg_style else fg_style,
.@"cell-background" => if (sty.flags.inverse) fg_style else bg_style,
else => unreachable,
};
} else
// Otherwise, use the background color.
self.background_color orelse self.default_background_color;
} else self.background_color orelse self.default_background_color;

cell.r = cell_color.r;
cell.g = cell_color.g;
Expand Down

0 comments on commit 6444db4

Please sign in to comment.