colors config: crossed-out text formatting support

to allow
```
"diff removed" = { crossed-out=true }
```
This commit is contained in:
shoce
2026-06-28 17:27:20 +07:00
committed by Yuya Nishihara
parent e0ef08ed38
commit 69e1e152fe
5 changed files with 28 additions and 6 deletions

View File

@@ -51,6 +51,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* Add a `forks()` revset function that yields all commits with more than 1 child.
* `colors` config now supports crossed-out text styling with
`{ crossed-out = true }`.
### Fixed bugs
* On Windows, querying a path's file identity no longer follows symbolic links,

View File

@@ -397,6 +397,9 @@
"underline": {
"type": "boolean"
},
"crossed-out": {
"type": "boolean"
},
"reverse": {
"type": "boolean"
}

View File

@@ -300,6 +300,7 @@ pub struct Style {
pub dim: Option<bool>,
pub italic: Option<bool>,
pub underline: Option<bool>,
pub crossed_out: Option<bool>,
pub reverse: Option<bool>,
}
@@ -311,6 +312,7 @@ impl Style {
self.dim = other.dim.or(self.dim);
self.italic = other.italic.or(self.italic);
self.underline = other.underline.or(self.underline);
self.crossed_out = other.crossed_out.or(self.crossed_out);
self.reverse = other.reverse.or(self.reverse);
}
}
@@ -443,6 +445,13 @@ impl<W: Write> ColorFormatter<W> {
queue!(self.output, SetAttribute(Attribute::NoUnderline))?;
}
}
if new_style.crossed_out != self.current_style.crossed_out {
if new_style.crossed_out.unwrap_or_default() {
queue!(self.output, SetAttribute(Attribute::CrossedOut))?;
} else {
queue!(self.output, SetAttribute(Attribute::NotCrossedOut))?;
}
}
if new_style.reverse != self.current_style.reverse {
if new_style.reverse.unwrap_or_default() {
queue!(self.output, SetAttribute(Attribute::Reverse))?;
@@ -491,6 +500,7 @@ fn rules_from_config(config: &StackedConfig) -> Result<Rules, ConfigGetError> {
dim: None,
italic: None,
underline: None,
crossed_out: None,
reverse: None,
})
} else if value.is_inline_table() {
@@ -1050,8 +1060,9 @@ mod tests {
colors.dim_font = { dim = true }
colors.italic_text = { italic = true }
colors.underlined_text = { underline = true }
colors.crossed_out_text = { crossed-out = true }
colors.reversed_colors = { reverse = true }
colors.multiple = { fg = "green", bg = "yellow", bold = true, italic = true, underline = true, reverse = true }
colors.multiple = { fg = "green", bg = "yellow", bold = true, italic = true, underline = true, crossed-out = true, reverse = true }
"#,
);
let mut output: Vec<u8> = vec![];
@@ -1080,6 +1091,10 @@ mod tests {
write!(formatter, " underlined only ")?;
formatter.pop_label();
writeln!(formatter)?;
formatter.push_label("crossed_out_text");
write!(formatter, " crossed-out only ")?;
formatter.pop_label();
writeln!(formatter)?;
formatter.push_label("reversed_colors");
write!(formatter, " reverse only ")?;
formatter.pop_label();
@@ -1102,8 +1117,9 @@ mod tests {
 dim only 
 italic only 
 underlined only 
 crossed-out only 
 reverse only 
 single rule 
 single rule 
 two rules 
[EOF]
");

View File

@@ -191,8 +191,8 @@ commit_id = "ansi-color-81"
If you use a string value for a color, as in the examples above, it will be used
for the foreground color. You can also set the background color, reverse colors
(swap foreground and background), or make the text bold, dim, italic, or
underlined. For that, you need to use a table:
(swap foreground and background), or make the text bold, dim, italic,
underlined, or crossed-out. For that, you need to use a table:
```toml
[colors]

View File

@@ -143,8 +143,8 @@ commit_id = "ansi-color-81"
If you use a string value for a color, as in the examples above, it will be used
for the foreground color. You can also set the background color, reverse colors
(swap foreground and background), or make the text bold, dim, italic, or
underlined. For that, you need to use a table:
(swap foreground and background), or make the text bold, dim, italic,
underlined, or crossed-out. For that, you need to use a table:
```toml
[colors]