mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-24 12:48:55 +00:00
formatter: allow using "default" terminal color
The "default" color resets the terminal color to default.
This commit is contained in:
parent
e468f9c97a
commit
c735d92e8c
4 changed files with 39 additions and 1 deletions
|
@ -72,6 +72,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
* The progress display on `jj git clone/fetch` now includes the downloaded size.
|
||||
|
||||
* The formatter now supports a "default" color that can override another color
|
||||
defined by a parent style.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
* Modify/delete conflicts now include context lines
|
||||
|
|
|
@ -92,8 +92,11 @@ The following colors are available:
|
|||
* magenta
|
||||
* cyan
|
||||
* white
|
||||
* default
|
||||
|
||||
They each come in a bright version too, e.g. "bright red".
|
||||
All of them but "default" come in a bright version too, e.g. "bright red". The
|
||||
"default" color can be used to override a color defined by a parent style
|
||||
(explained below).
|
||||
|
||||
If you use a string value for a color, as in the example above, it will be used
|
||||
for the foreground color. You can also set the background color, or make the
|
||||
|
|
|
@ -128,6 +128,7 @@
|
|||
"definitions": {
|
||||
"colors": {
|
||||
"enum": [
|
||||
"default",
|
||||
"black",
|
||||
"red",
|
||||
"green",
|
||||
|
|
|
@ -372,6 +372,7 @@ fn rules_from_config(config: &config::Config) -> Result<Rules, config::ConfigErr
|
|||
|
||||
fn color_for_name(color_name: &str) -> Result<Color, config::ConfigError> {
|
||||
match color_name {
|
||||
"default" => Ok(Color::Reset),
|
||||
"black" => Ok(Color::Black),
|
||||
"red" => Ok(Color::DarkRed),
|
||||
"green" => Ok(Color::DarkGreen),
|
||||
|
@ -861,6 +862,36 @@ mod tests {
|
|||
@"invalid color: bloo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_color_formatter_normal_color() {
|
||||
// The "default" color resets the color. It is possible to reset only the
|
||||
// background or only the foreground.
|
||||
let config = config_from_string(
|
||||
r#"
|
||||
colors."outer" = {bg="yellow", fg="blue"}
|
||||
colors."outer default_fg" = "default"
|
||||
colors."outer default_bg" = {bg = "default"}
|
||||
"#,
|
||||
);
|
||||
let mut output: Vec<u8> = vec![];
|
||||
let mut formatter = ColorFormatter::for_config(&mut output, &config).unwrap();
|
||||
formatter.push_label("outer").unwrap();
|
||||
formatter.write_str("Blue on yellow, ").unwrap();
|
||||
formatter.push_label("default_fg").unwrap();
|
||||
formatter.write_str(" default fg, ").unwrap();
|
||||
formatter.pop_label().unwrap();
|
||||
formatter.write_str(" and back.\nBlue on yellow, ").unwrap();
|
||||
formatter.push_label("default_bg").unwrap();
|
||||
formatter.write_str(" default bg, ").unwrap();
|
||||
formatter.pop_label().unwrap();
|
||||
formatter.write_str(" and back.").unwrap();
|
||||
insta::assert_snapshot!(String::from_utf8(output).unwrap(),
|
||||
@r###"
|
||||
[38;5;4m[48;5;3mBlue on yellow, [39m default fg, [38;5;4m and back.[39m[49m
|
||||
[38;5;4m[48;5;3mBlue on yellow, [49m default bg, [48;5;3m and back.
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_color_formatter_sibling() {
|
||||
// A partial match on one rule does not eliminate other rules.
|
||||
|
|
Loading…
Reference in a new issue