formatter: remove hack for making bright colors bold

We can now configure the working-copy commit and the head operation to
use bold font, so we no longer need the hack to make bright colors
bold.
This commit is contained in:
Martin von Zweigbergk 2023-01-07 10:16:57 -08:00 committed by Martin von Zweigbergk
parent e93a347f9e
commit 2a9c37a693
5 changed files with 25 additions and 48 deletions

View file

@ -20,11 +20,7 @@
"divergent change_id"="red"
"conflict" = "red"
# TODO: This near-duplication of the lines above is unfortunate. Should we
# allow adding and clearing the "bright" bit somehow? Or should we instead
# use a different background color? (We don't have support for background
# colors yet.)
"working_copy" = { bold = true }
"working_copy commit_id" = "bright blue"
"working_copy change_id" = "bright magenta"
"working_copy email" = "bright yellow"
@ -48,6 +44,7 @@
"op-log user" = "yellow"
"op-log time" = "cyan"
"op-log tags" = "white"
"op-log head" = { bold = true }
"op-log head id" = "bright blue"
"op-log head user" = "bright yellow"
"op-log head time" = "bright cyan"

View file

@ -231,15 +231,6 @@ impl<W: Write> ColorFormatter<W> {
fn write_new_style(&mut self) -> io::Result<()> {
let new_style = self.current_style();
if new_style != self.current_style {
// For now, make bright colors imply bold font. That better matches our
// behavior from when we used ANSI codes 30-37 plus an optional 1 for
// bold/bright (we now use code 38 for setting foreground color).
// TODO: Make boldness configurable separately from color
if !is_bright(&self.current_style.fg_color) && is_bright(&new_style.fg_color) {
queue!(self.output, SetAttribute(Attribute::Bold))?;
} else if !is_bright(&new_style.fg_color) && is_bright(&self.current_style.fg_color) {
queue!(self.output, SetAttribute(Attribute::Reset))?;
}
if new_style.bold != self.current_style.bold {
if new_style.bold.unwrap_or_default() {
queue!(self.output, SetAttribute(Attribute::Bold))?;
@ -270,20 +261,6 @@ impl<W: Write> ColorFormatter<W> {
}
}
fn is_bright(color: &Option<Color>) -> bool {
matches!(
color.unwrap_or(Color::Reset),
Color::DarkGrey
| Color::Red
| Color::Green
| Color::Yellow
| Color::Blue
| Color::Magenta
| Color::Cyan
| Color::White
)
}
fn rules_from_config(config: &config::Config) -> HashMap<Vec<String>, Style> {
let mut result = HashMap::new();
if let Ok(table) = config.get_table("colors") {
@ -439,14 +416,14 @@ mod tests {
 magenta 
 cyan 
 white 
 bright black 
 bright red 
 bright green 
 bright yellow 
 bright blue 
 bright magenta 
 bright cyan 
 bright white 
 bright black 
 bright red 
 bright green 
 bright yellow 
 bright blue 
 bright magenta 
 bright cyan 
 bright white 
"###);
}

View file

@ -75,8 +75,9 @@ fn test_log_default() {
// Color
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
@ ffdaa62087a2 test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9de54178d59d
| description 1
@ ffdaa62087a2 test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9de54178d59d
| description 1
| 
o 9a45c67d3e96 test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264ae97
| add a file
o 000000000000  1970-01-01 00:00:00.000 +00:00 000000000000
@ -86,9 +87,9 @@ fn test_log_default() {
// Color without graph
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always", "--no-graph"]);
insta::assert_snapshot!(stdout, @r###"
ffdaa62087a2 test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9de54178d59d
description 1
9a45c67d3e96 test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264ae97
ffdaa62087a2 test.user@example.com 2001-02-03 04:05:09.000 +07:00 my-branch 9de54178d59d
description 1
9a45c67d3e96 test.user@example.com 2001-02-03 04:05:08.000 +07:00 4291e264ae97
add a file
000000000000  1970-01-01 00:00:00.000 +00:00 000000000000
(no description set)
@ -129,12 +130,14 @@ fn test_log_default_divergence() {
"###);
// Color
// TODO: We shouldn't get a blank line after "description 1"
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
o 9a45c67d3e96?? test.user@example.com 2001-02-03 04:05:10.000 +07:00 8979953d4c67
| description 2
| @ 9a45c67d3e96?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e633c
|/ description 1
| @ 9a45c67d3e96?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7a17d52e633c
|/ description 1
| 
o 000000000000  1970-01-01 00:00:00.000 +00:00 000000000000
(no description set)
"###);

View file

@ -182,7 +182,7 @@ fn test_color_config() {
// Test that --color=always is respected.
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000
"###);
@ -193,7 +193,7 @@ color="always""#,
);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000
"###);
@ -249,7 +249,7 @@ color="always""#,
test_env.add_env_var("NO_COLOR", "");
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000
"###);

View file

@ -573,8 +573,8 @@ fn test_graph_template_color() {
// TODO: The color codes shouldn't span the graph lines, and we shouldn't get an
// extra line at the end
insta::assert_snapshot!(stdout, @r###"
@ single line
| 
@ single line
| 
o first line
| second line
| third line