mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Add config option to change selection color
This commit is contained in:
parent
62c1d999e1
commit
0b9ae4ce93
4 changed files with 35 additions and 2 deletions
|
@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Dynamic title support on Windows
|
- Dynamic title support on Windows
|
||||||
- Ability to specify starting position with the `--position` flag
|
- Ability to specify starting position with the `--position` flag
|
||||||
- New configuration field `window.position` allows specifying the starting position
|
- New configuration field `window.position` allows specifying the starting position
|
||||||
|
- Added the ability to change the selection color
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,15 @@ colors:
|
||||||
#cursor:
|
#cursor:
|
||||||
# text: '0x000000'
|
# text: '0x000000'
|
||||||
# cursor: '0xffffff'
|
# cursor: '0xffffff'
|
||||||
|
|
||||||
|
# Selection colors
|
||||||
|
#
|
||||||
|
# Colors which should be used to draw the selection area. If selection
|
||||||
|
# background is unset, selection color will be the inverse of the cell colors.
|
||||||
|
# If only text is unset the cell text color will remain the same.
|
||||||
|
#selection:
|
||||||
|
# text: '0xeaeaea'
|
||||||
|
# background: '0x404040'
|
||||||
|
|
||||||
# Normal colors
|
# Normal colors
|
||||||
normal:
|
normal:
|
||||||
|
|
|
@ -1285,6 +1285,8 @@ pub struct Colors {
|
||||||
pub primary: PrimaryColors,
|
pub primary: PrimaryColors,
|
||||||
#[serde(deserialize_with = "failure_default")]
|
#[serde(deserialize_with = "failure_default")]
|
||||||
pub cursor: CursorColors,
|
pub cursor: CursorColors,
|
||||||
|
#[serde(deserialize_with = "failure_default")]
|
||||||
|
pub selection: SelectionColors,
|
||||||
#[serde(deserialize_with = "deserialize_normal_colors")]
|
#[serde(deserialize_with = "deserialize_normal_colors")]
|
||||||
pub normal: AnsiColors,
|
pub normal: AnsiColors,
|
||||||
#[serde(deserialize_with = "deserialize_bright_colors")]
|
#[serde(deserialize_with = "deserialize_bright_colors")]
|
||||||
|
@ -1300,6 +1302,7 @@ impl Default for Colors {
|
||||||
Colors {
|
Colors {
|
||||||
primary: Default::default(),
|
primary: Default::default(),
|
||||||
cursor: Default::default(),
|
cursor: Default::default(),
|
||||||
|
selection: Default::default(),
|
||||||
normal: default_normal_colors(),
|
normal: default_normal_colors(),
|
||||||
bright: default_bright_colors(),
|
bright: default_bright_colors(),
|
||||||
dim: Default::default(),
|
dim: Default::default(),
|
||||||
|
@ -1421,6 +1424,15 @@ pub struct CursorColors {
|
||||||
pub cursor: Option<Rgb>,
|
pub cursor: Option<Rgb>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
#[derive(Debug, Copy, Clone, Default, Deserialize, PartialEq, Eq)]
|
||||||
|
pub struct SelectionColors {
|
||||||
|
#[serde(deserialize_with = "deserialize_optional_color")]
|
||||||
|
pub text: Option<Rgb>,
|
||||||
|
#[serde(deserialize_with = "deserialize_optional_color")]
|
||||||
|
pub background: Option<Rgb>,
|
||||||
|
}
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, PartialEq, Eq)]
|
||||||
pub struct PrimaryColors {
|
pub struct PrimaryColors {
|
||||||
|
|
|
@ -455,17 +455,28 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
|
||||||
(cell, selected)
|
(cell, selected)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply inversion and lookup RGB values
|
// Lookup RGB values
|
||||||
let mut fg_rgb = self.compute_fg_rgb(cell.fg, &cell);
|
let mut fg_rgb = self.compute_fg_rgb(cell.fg, &cell);
|
||||||
let mut bg_rgb = self.compute_bg_rgb(cell.bg);
|
let mut bg_rgb = self.compute_bg_rgb(cell.bg);
|
||||||
|
|
||||||
let bg_alpha = if selected ^ cell.inverse() {
|
let selection_background = self.config.colors().selection.background;
|
||||||
|
let bg_alpha = if let (true, Some(col)) = (selected, selection_background) {
|
||||||
|
// Override selection background with config colors
|
||||||
|
bg_rgb = col;
|
||||||
|
1.0
|
||||||
|
} else if selected ^ cell.inverse() {
|
||||||
|
// Invert cell fg and bg colors
|
||||||
mem::swap(&mut fg_rgb, &mut bg_rgb);
|
mem::swap(&mut fg_rgb, &mut bg_rgb);
|
||||||
self.compute_bg_alpha(cell.fg)
|
self.compute_bg_alpha(cell.fg)
|
||||||
} else {
|
} else {
|
||||||
self.compute_bg_alpha(cell.bg)
|
self.compute_bg_alpha(cell.bg)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Override selection text with config colors
|
||||||
|
if let (true, Some(col)) = (selected, self.config.colors().selection.text) {
|
||||||
|
fg_rgb = col;
|
||||||
|
}
|
||||||
|
|
||||||
return Some(RenderableCell {
|
return Some(RenderableCell {
|
||||||
line: cell.line,
|
line: cell.line,
|
||||||
column: cell.column,
|
column: cell.column,
|
||||||
|
|
Loading…
Reference in a new issue