mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
Squash and rebase, updated refactored version with selection and cursor cell color changes
This commit is contained in:

committed by
Mitchell Hashimoto

parent
9e341a3d60
commit
95de198761
@ -591,7 +591,7 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
|
|||||||
/// the selection color is just the inverted window background and foreground
|
/// the selection color is just the inverted window background and foreground
|
||||||
/// (note: not to be confused with the cell bg/fg).
|
/// (note: not to be confused with the cell bg/fg).
|
||||||
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
|
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
|
||||||
/// Since version 1.1.1, this can also be set to `cell-foreground` to match
|
/// Since version 1.2.0, this can also be set to `cell-foreground` to match
|
||||||
/// the cell foreground color, or `cell-background` to match the cell
|
/// the cell foreground color, or `cell-background` to match the cell
|
||||||
/// background color.
|
/// background color.
|
||||||
@"selection-foreground": ?DynamicColor = null,
|
@"selection-foreground": ?DynamicColor = null,
|
||||||
@ -604,7 +604,7 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF },
|
|||||||
/// If you select across cells with differing foregrounds and backgrounds, the
|
/// If you select across cells with differing foregrounds and backgrounds, the
|
||||||
/// selection color will vary across the selection.
|
/// selection color will vary across the selection.
|
||||||
///
|
///
|
||||||
/// Warning: This option has been deprecated as of version 1.1.1. Instead,
|
/// Warning: This option has been deprecated as of version 1.2.0. Instead,
|
||||||
/// users should set `selection-foreground` and `selection-background` to
|
/// users should set `selection-foreground` and `selection-background` to
|
||||||
/// `cell-background` and `cell-foreground`, respectively.
|
/// `cell-background` and `cell-foreground`, respectively.
|
||||||
@"selection-invert-fg-bg": bool = false,
|
@"selection-invert-fg-bg": bool = false,
|
||||||
@ -652,7 +652,7 @@ palette: Palette = .{},
|
|||||||
|
|
||||||
/// The color of the cursor. If this is not set, a default will be chosen.
|
/// The color of the cursor. If this is not set, a default will be chosen.
|
||||||
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
|
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
|
||||||
/// Since version 1.1.1, this can also be set to `cell-foreground` to match
|
/// Since version 1.2.0, this can also be set to `cell-foreground` to match
|
||||||
/// the cell foreground color, or `cell-background` to match the cell
|
/// the cell foreground color, or `cell-background` to match the cell
|
||||||
/// background color.
|
/// background color.
|
||||||
@"cursor-color": ?DynamicColor = null,
|
@"cursor-color": ?DynamicColor = null,
|
||||||
@ -660,7 +660,7 @@ palette: Palette = .{},
|
|||||||
/// Swap the foreground and background colors of the cell under the cursor. This
|
/// Swap the foreground and background colors of the cell under the cursor. This
|
||||||
/// option overrides the `cursor-color` and `cursor-text` options.
|
/// option overrides the `cursor-color` and `cursor-text` options.
|
||||||
///
|
///
|
||||||
/// Warning: This option has been deprecated as of version 1.1.1. Instead,
|
/// Warning: This option has been deprecated as of version 1.2.0. Instead,
|
||||||
/// users should set `cursor-color` and `cursor-text` to `cell-foreground` and
|
/// users should set `cursor-color` and `cursor-text` to `cell-foreground` and
|
||||||
/// `cell-background`, respectively.
|
/// `cell-background`, respectively.
|
||||||
@"cursor-invert-fg-bg": bool = false,
|
@"cursor-invert-fg-bg": bool = false,
|
||||||
@ -713,7 +713,7 @@ palette: Palette = .{},
|
|||||||
/// The color of the text under the cursor. If this is not set, a default will
|
/// The color of the text under the cursor. If this is not set, a default will
|
||||||
/// be chosen.
|
/// be chosen.
|
||||||
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
|
/// Specified as either hex (`#RRGGBB` or `RRGGBB`) or a named X11 color.
|
||||||
/// Since version 1.1.1, this can also be set to `cell-foreground` to match
|
/// Since version 1.2.0, this can also be set to `cell-foreground` to match
|
||||||
/// the cell foreground color, or `cell-background` to match the cell
|
/// the cell foreground color, or `cell-background` to match the cell
|
||||||
/// background color.
|
/// background color.
|
||||||
@"cursor-text": ?DynamicColor = null,
|
@"cursor-text": ?DynamicColor = null,
|
||||||
|
@ -133,12 +133,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
/// This is cursor color as set in the user's config, if any. If no cursor color
|
/// This is cursor color as set in the user's config, if any. If no cursor color
|
||||||
/// is set in the user's config, then the cursor color is determined by the
|
/// is set in the user's config, then the cursor color is determined by the
|
||||||
/// current foreground color.
|
/// current foreground color.
|
||||||
default_cursor_color: ?terminal.color.RGB,
|
default_cursor_color: ?configpkg.Config.DynamicColor,
|
||||||
|
|
||||||
/// When `cursor_color` is null, swap the foreground and background colors of
|
|
||||||
/// the cell under the cursor for the cursor color. Otherwise, use the default
|
|
||||||
/// foreground color as the cursor color.
|
|
||||||
cursor_invert: bool,
|
|
||||||
|
|
||||||
/// The current set of cells to render. This is rebuilt on every frame
|
/// The current set of cells to render. This is rebuilt on every frame
|
||||||
/// but we keep this around so that we don't reallocate. Each set of
|
/// but we keep this around so that we don't reallocate. Each set of
|
||||||
@ -514,16 +509,14 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
font_features: std.ArrayListUnmanaged([:0]const u8),
|
font_features: std.ArrayListUnmanaged([:0]const u8),
|
||||||
font_styles: font.CodepointResolver.StyleStatus,
|
font_styles: font.CodepointResolver.StyleStatus,
|
||||||
font_shaping_break: configpkg.FontShapingBreak,
|
font_shaping_break: configpkg.FontShapingBreak,
|
||||||
cursor_color: ?terminal.color.RGB,
|
cursor_color: ?configpkg.Config.DynamicColor,
|
||||||
cursor_invert: bool,
|
|
||||||
cursor_opacity: f64,
|
cursor_opacity: f64,
|
||||||
cursor_text: ?terminal.color.RGB,
|
cursor_text: ?configpkg.Config.DynamicColor,
|
||||||
background: terminal.color.RGB,
|
background: terminal.color.RGB,
|
||||||
background_opacity: f64,
|
background_opacity: f64,
|
||||||
foreground: terminal.color.RGB,
|
foreground: terminal.color.RGB,
|
||||||
selection_background: ?terminal.color.RGB,
|
selection_background: ?configpkg.Config.DynamicColor,
|
||||||
selection_foreground: ?terminal.color.RGB,
|
selection_foreground: ?configpkg.Config.DynamicColor,
|
||||||
invert_selection_fg_bg: bool,
|
|
||||||
bold_is_bright: bool,
|
bold_is_bright: bool,
|
||||||
min_contrast: f32,
|
min_contrast: f32,
|
||||||
padding_color: configpkg.WindowPaddingColor,
|
padding_color: configpkg.WindowPaddingColor,
|
||||||
@ -571,8 +564,6 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
config.link.links.items,
|
config.link.links.items,
|
||||||
);
|
);
|
||||||
|
|
||||||
const cursor_invert = config.@"cursor-invert-fg-bg";
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
||||||
.font_thicken = config.@"font-thicken",
|
.font_thicken = config.@"font-thicken",
|
||||||
@ -581,36 +572,18 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
.font_styles = font_styles,
|
.font_styles = font_styles,
|
||||||
.font_shaping_break = config.@"font-shaping-break",
|
.font_shaping_break = config.@"font-shaping-break",
|
||||||
|
|
||||||
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)
|
.cursor_color = config.@"cursor-color",
|
||||||
config.@"cursor-color".?.toTerminalRGB()
|
.cursor_text = config.@"cursor-text",
|
||||||
else
|
|
||||||
null,
|
|
||||||
|
|
||||||
.cursor_invert = cursor_invert,
|
|
||||||
|
|
||||||
.cursor_text = if (config.@"cursor-text") |txt|
|
|
||||||
txt.toTerminalRGB()
|
|
||||||
else
|
|
||||||
null,
|
|
||||||
|
|
||||||
.cursor_opacity = @max(0, @min(1, config.@"cursor-opacity")),
|
.cursor_opacity = @max(0, @min(1, config.@"cursor-opacity")),
|
||||||
|
|
||||||
.background = config.background.toTerminalRGB(),
|
.background = config.background.toTerminalRGB(),
|
||||||
.foreground = config.foreground.toTerminalRGB(),
|
.foreground = config.foreground.toTerminalRGB(),
|
||||||
.invert_selection_fg_bg = config.@"selection-invert-fg-bg",
|
|
||||||
.bold_is_bright = config.@"bold-is-bright",
|
.bold_is_bright = config.@"bold-is-bright",
|
||||||
.min_contrast = @floatCast(config.@"minimum-contrast"),
|
.min_contrast = @floatCast(config.@"minimum-contrast"),
|
||||||
.padding_color = config.@"window-padding-color",
|
.padding_color = config.@"window-padding-color",
|
||||||
|
|
||||||
.selection_background = if (config.@"selection-background") |bg|
|
.selection_background = config.@"selection-background",
|
||||||
bg.toTerminalRGB()
|
.selection_foreground = config.@"selection-foreground",
|
||||||
else
|
|
||||||
null,
|
|
||||||
|
|
||||||
.selection_foreground = if (config.@"selection-foreground") |bg|
|
|
||||||
bg.toTerminalRGB()
|
|
||||||
else
|
|
||||||
null,
|
|
||||||
|
|
||||||
.custom_shaders = custom_shaders,
|
.custom_shaders = custom_shaders,
|
||||||
.bg_image = bg_image,
|
.bg_image = bg_image,
|
||||||
@ -703,7 +676,6 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
.default_background_color = options.config.background,
|
.default_background_color = options.config.background,
|
||||||
.cursor_color = null,
|
.cursor_color = null,
|
||||||
.default_cursor_color = options.config.cursor_color,
|
.default_cursor_color = options.config.cursor_color,
|
||||||
.cursor_invert = options.config.cursor_invert,
|
|
||||||
|
|
||||||
// Render state
|
// Render state
|
||||||
.cells = .{},
|
.cells = .{},
|
||||||
@ -2079,8 +2051,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
// Set our new colors
|
// Set our new colors
|
||||||
self.default_background_color = config.background;
|
self.default_background_color = config.background;
|
||||||
self.default_foreground_color = config.foreground;
|
self.default_foreground_color = config.foreground;
|
||||||
self.default_cursor_color = if (!config.cursor_invert) config.cursor_color else null;
|
self.default_cursor_color = config.cursor_color;
|
||||||
self.cursor_invert = config.cursor_invert;
|
|
||||||
|
|
||||||
const bg_image_config_changed =
|
const bg_image_config_changed =
|
||||||
self.config.bg_image_fit != config.bg_image_fit or
|
self.config.bg_image_fit != config.bg_image_fit or
|
||||||
@ -2583,22 +2554,15 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
// The final background color for the cell.
|
// The final background color for the cell.
|
||||||
const bg = bg: {
|
const bg = bg: {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
break :bg if (self.config.invert_selection_fg_bg)
|
break :bg if (self.config.selection_background) |selection_color|
|
||||||
if (style.flags.inverse)
|
// Use the selection background if set, otherwise the default fg color.
|
||||||
// Cell is selected with invert selection fg/bg
|
switch (selection_color) {
|
||||||
// enabled, and the cell has the inverse style
|
.color => selection_color.color.toTerminalRGB(),
|
||||||
// flag, so they cancel out and we get the normal
|
.@"cell-foreground" => if (style.flags.inverse) bg_style else fg_style,
|
||||||
// bg color.
|
.@"cell-background" => if (style.flags.inverse) fg_style else bg_style,
|
||||||
bg_style
|
}
|
||||||
else
|
|
||||||
// If it doesn't have the inverse style
|
|
||||||
// flag then we use the fg color instead.
|
|
||||||
fg_style
|
|
||||||
else
|
else
|
||||||
// If we don't have invert selection fg/bg set then we
|
self.foreground_color orelse self.default_foreground_color;
|
||||||
// just use the selection background if set, otherwise
|
|
||||||
// the default fg color.
|
|
||||||
break :bg self.config.selection_background orelse self.foreground_color orelse self.default_foreground_color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not selected
|
// Not selected
|
||||||
@ -2618,20 +2582,26 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fg = fg: {
|
const fg = fg: {
|
||||||
if (selected and !self.config.invert_selection_fg_bg) {
|
const final_bg = bg_style orelse self.background_color orelse self.default_background_color;
|
||||||
// If we don't have invert selection fg/bg set
|
|
||||||
// then we just use the selection foreground if
|
|
||||||
// set, otherwise the default bg color.
|
|
||||||
break :fg self.config.selection_foreground orelse self.background_color orelse self.default_background_color;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Whether we need to use the bg color as our fg color:
|
// Whether we need to use the bg color as our fg color:
|
||||||
|
// - Cell is selected, inverted, and set to cell-foreground
|
||||||
|
// - Cell is selected, not inverted, and set to cell-background
|
||||||
// - Cell is inverted and not selected
|
// - Cell is inverted and not selected
|
||||||
// - Cell is selected and not inverted
|
if (selected) {
|
||||||
// Note: if selected then invert sel fg / bg must be
|
// Use the selection foreground if set, otherwise the default bg color.
|
||||||
// false since we separately handle it if true above.
|
break :fg if (self.config.selection_foreground) |selection_color|
|
||||||
break :fg if (style.flags.inverse != selected)
|
switch (selection_color) {
|
||||||
bg_style orelse self.background_color orelse self.default_background_color
|
.color => selection_color.color.toTerminalRGB(),
|
||||||
|
.@"cell-foreground" => if (style.flags.inverse) final_bg else fg_style,
|
||||||
|
.@"cell-background" => if (style.flags.inverse) fg_style else final_bg,
|
||||||
|
}
|
||||||
|
else
|
||||||
|
self.background_color orelse self.default_background_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
break :fg if (style.flags.inverse)
|
||||||
|
final_bg
|
||||||
else
|
else
|
||||||
fg_style;
|
fg_style;
|
||||||
};
|
};
|
||||||
@ -2817,19 +2787,25 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
|
|
||||||
// Prepare the cursor cell contents.
|
// Prepare the cursor cell contents.
|
||||||
const style = cursor_style_ orelse break :cursor;
|
const style = cursor_style_ orelse break :cursor;
|
||||||
const cursor_color = self.cursor_color orelse self.default_cursor_color orelse color: {
|
const cursor_color = self.cursor_color orelse if (self.default_cursor_color) |color| color: {
|
||||||
if (self.cursor_invert) {
|
// If cursor-color is set, then compute the correct color.
|
||||||
// Use the foreground color from the cell under the cursor, if any.
|
// Otherwise, use the foreground color
|
||||||
const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
|
if (color == .color) {
|
||||||
break :color if (sty.flags.inverse)
|
// Use the color set by cursor-color, if any.
|
||||||
// If the cell is reversed, use background color instead.
|
break :color color.color.toTerminalRGB();
|
||||||
(sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color)
|
|
||||||
else
|
|
||||||
(sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color);
|
|
||||||
} else {
|
|
||||||
break :color self.foreground_color orelse self.default_foreground_color;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
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) {
|
||||||
|
// 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 self.foreground_color orelse self.default_foreground_color;
|
||||||
|
|
||||||
self.addCursor(screen, style, cursor_color);
|
self.addCursor(screen, style, cursor_color);
|
||||||
|
|
||||||
@ -2853,18 +2829,25 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
|||||||
.wide, .spacer_tail => true,
|
.wide, .spacer_tail => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const uniform_color = if (self.cursor_invert) blk: {
|
const uniform_color = if (self.config.cursor_text) |txt| blk: {
|
||||||
// Use the background color from the cell under the cursor, if any.
|
// 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 sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
|
||||||
break :blk if (sty.flags.inverse)
|
const fg_style = sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color;
|
||||||
// If the cell is reversed, use foreground color instead.
|
const bg_style = sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color;
|
||||||
(sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color orelse self.default_foreground_color)
|
|
||||||
else
|
break :blk switch (txt) {
|
||||||
(sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color orelse self.default_background_color);
|
// If the cell is reversed, use the opposite cell color instead.
|
||||||
} else if (self.config.cursor_text) |txt|
|
.@"cell-foreground" => if (sty.flags.inverse) bg_style else fg_style,
|
||||||
txt
|
.@"cell-background" => if (sty.flags.inverse) fg_style else bg_style,
|
||||||
else
|
else => unreachable,
|
||||||
self.background_color orelse self.default_background_color;
|
};
|
||||||
|
} else self.background_color orelse self.default_background_color;
|
||||||
|
|
||||||
self.uniforms.cursor_color = .{
|
self.uniforms.cursor_color = .{
|
||||||
uniform_color.r,
|
uniform_color.r,
|
||||||
|
Reference in New Issue
Block a user