mirror of
https://github.com/wez/wezterm.git
synced 2024-11-27 12:23:46 +03:00
gui: allow specifying colors for copy mode and quickselect
refs: https://github.com/wez/wezterm/issues/2320 ```lua return { colors = { copy_mode_active_highlight_fg={Color="red"}, copy_mode_active_highlight_bg={Color="blue"}, copy_mode_inactive_highlight_fg={AnsiColor="Black"}, copy_mode_inactive_highlight_bg={AnsiColor="White"}, quick_select_label_fg={Color="white"}, quick_select_label_bg={Color="blue"}, quick_select_match_fg={Color="grey"}, quick_select_match_bg={Color="skyblue"}, } } ```
This commit is contained in:
parent
718a021817
commit
7e3b35303c
@ -3,7 +3,8 @@ use luahelper::impl_lua_conversion_dynamic;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::str::FromStr;
|
||||
use termwiz::cell::CellAttributes;
|
||||
pub use termwiz::color::{ColorSpec, RgbColor, SrgbaTuple};
|
||||
use termwiz::color::ColorSpec as TWColorSpec;
|
||||
pub use termwiz::color::{AnsiColor, ColorAttribute, RgbColor, SrgbaTuple};
|
||||
use wezterm_dynamic::{FromDynamic, ToDynamic};
|
||||
use wezterm_term::color::ColorPalette;
|
||||
|
||||
@ -90,6 +91,39 @@ impl TryFrom<String> for RgbaColor {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ColorSpec {
|
||||
AnsiColor(AnsiColor),
|
||||
Color(RgbaColor),
|
||||
Default,
|
||||
}
|
||||
|
||||
impl From<AnsiColor> for ColorSpec {
|
||||
fn from(color: AnsiColor) -> ColorSpec {
|
||||
Self::AnsiColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<ColorAttribute> for ColorSpec {
|
||||
fn into(self) -> ColorAttribute {
|
||||
match self {
|
||||
Self::AnsiColor(c) => ColorAttribute::PaletteIndex(c.into()),
|
||||
Self::Color(RgbaColor { color }) => ColorAttribute::TrueColorWithDefaultFallback(color),
|
||||
Self::Default => ColorAttribute::Default,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<TWColorSpec> for ColorSpec {
|
||||
fn into(self) -> TWColorSpec {
|
||||
match self {
|
||||
Self::AnsiColor(c) => c.into(),
|
||||
Self::Color(RgbaColor { color }) => TWColorSpec::TrueColor(color),
|
||||
Self::Default => TWColorSpec::Default,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, FromDynamic, ToDynamic)]
|
||||
pub struct Palette {
|
||||
/// The text color to use when the attributes are reset to default
|
||||
@ -124,6 +158,16 @@ pub struct Palette {
|
||||
pub visual_bell: Option<RgbaColor>,
|
||||
/// The color to use for the cursor when a dead key or leader state is active
|
||||
pub compose_cursor: Option<RgbaColor>,
|
||||
|
||||
pub copy_mode_active_highlight_fg: Option<ColorSpec>,
|
||||
pub copy_mode_active_highlight_bg: Option<ColorSpec>,
|
||||
pub copy_mode_inactive_highlight_fg: Option<ColorSpec>,
|
||||
pub copy_mode_inactive_highlight_bg: Option<ColorSpec>,
|
||||
|
||||
pub quick_select_label_fg: Option<ColorSpec>,
|
||||
pub quick_select_label_bg: Option<ColorSpec>,
|
||||
pub quick_select_match_fg: Option<ColorSpec>,
|
||||
pub quick_select_match_bg: Option<ColorSpec>,
|
||||
}
|
||||
impl_lua_conversion_dynamic!(Palette);
|
||||
|
||||
@ -238,8 +282,8 @@ impl TabBarColor {
|
||||
.set_underline(self.underline)
|
||||
.set_italic(self.italic)
|
||||
.set_strikethrough(self.strikethrough)
|
||||
.set_background(ColorSpec::TrueColor(*self.bg_color))
|
||||
.set_foreground(ColorSpec::TrueColor(*self.fg_color));
|
||||
.set_background(TWColorSpec::TrueColor(*self.bg_color))
|
||||
.set_foreground(TWColorSpec::TrueColor(*self.fg_color));
|
||||
attr
|
||||
}
|
||||
}
|
||||
|
@ -956,6 +956,9 @@ impl Pane for CopyOverlay {
|
||||
|
||||
let (top, mut lines) = self.delegate.get_lines(lines);
|
||||
|
||||
let config = config::configuration();
|
||||
let colors = &config.resolved_palette;
|
||||
|
||||
// Process the lines; for the search row we want to render instead
|
||||
// the search UI.
|
||||
// For rows with search results, we want to highlight the matching ranges
|
||||
@ -994,13 +997,29 @@ impl Pane for CopyOverlay {
|
||||
{
|
||||
if Some(m.result_index) == renderer.result_pos {
|
||||
cell.attrs_mut()
|
||||
.set_background(AnsiColor::Yellow)
|
||||
.set_foreground(AnsiColor::Black)
|
||||
.set_background(
|
||||
colors
|
||||
.copy_mode_active_highlight_bg
|
||||
.unwrap_or(AnsiColor::Yellow.into()),
|
||||
)
|
||||
.set_foreground(
|
||||
colors
|
||||
.copy_mode_active_highlight_fg
|
||||
.unwrap_or(AnsiColor::Black.into()),
|
||||
)
|
||||
.set_reverse(false);
|
||||
} else {
|
||||
cell.attrs_mut()
|
||||
.set_background(AnsiColor::Fuchsia)
|
||||
.set_foreground(AnsiColor::Black)
|
||||
.set_background(
|
||||
colors
|
||||
.copy_mode_inactive_highlight_bg
|
||||
.unwrap_or(AnsiColor::Fuchsia.into()),
|
||||
)
|
||||
.set_foreground(
|
||||
colors
|
||||
.copy_mode_inactive_highlight_fg
|
||||
.unwrap_or(AnsiColor::Black.into()),
|
||||
)
|
||||
.set_reverse(false);
|
||||
}
|
||||
}
|
||||
|
@ -458,6 +458,7 @@ impl Pane for QuickSelectOverlay {
|
||||
let dims = self.get_dimensions();
|
||||
|
||||
let (top, mut lines) = self.delegate.get_lines(lines);
|
||||
let colors = renderer.config.resolved_palette.clone();
|
||||
|
||||
// Process the lines; for the search row we want to render instead
|
||||
// the search UI.
|
||||
@ -492,8 +493,16 @@ impl Pane for QuickSelectOverlay {
|
||||
if let Some(cell) = line.cells_mut_for_attr_changes_only().get_mut(cell_idx)
|
||||
{
|
||||
cell.attrs_mut()
|
||||
.set_background(AnsiColor::Black)
|
||||
.set_foreground(AnsiColor::Green)
|
||||
.set_background(
|
||||
colors
|
||||
.quick_select_match_bg
|
||||
.unwrap_or(AnsiColor::Black.into()),
|
||||
)
|
||||
.set_foreground(
|
||||
colors
|
||||
.quick_select_match_fg
|
||||
.unwrap_or(AnsiColor::Green.into()),
|
||||
)
|
||||
.set_reverse(false);
|
||||
}
|
||||
}
|
||||
@ -502,9 +511,17 @@ impl Pane for QuickSelectOverlay {
|
||||
.get_cell(idx)
|
||||
.map(|cell| cell.attrs().clone())
|
||||
.unwrap_or_else(|| CellAttributes::default());
|
||||
attr.set_background(AnsiColor::Black)
|
||||
.set_foreground(AnsiColor::Olive)
|
||||
.set_reverse(false);
|
||||
attr.set_background(
|
||||
colors
|
||||
.quick_select_label_bg
|
||||
.unwrap_or(AnsiColor::Black.into()),
|
||||
)
|
||||
.set_foreground(
|
||||
colors
|
||||
.quick_select_label_fg
|
||||
.unwrap_or(AnsiColor::Olive.into()),
|
||||
)
|
||||
.set_reverse(false);
|
||||
line.set_cell(m.range.start + idx, Cell::new(c, attr), SEQ_ZERO);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user