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" "divergent change_id"="red"
"conflict" = "red" "conflict" = "red"
# TODO: This near-duplication of the lines above is unfortunate. Should we "working_copy" = { bold = true }
# 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 commit_id" = "bright blue" "working_copy commit_id" = "bright blue"
"working_copy change_id" = "bright magenta" "working_copy change_id" = "bright magenta"
"working_copy email" = "bright yellow" "working_copy email" = "bright yellow"
@ -48,6 +44,7 @@
"op-log user" = "yellow" "op-log user" = "yellow"
"op-log time" = "cyan" "op-log time" = "cyan"
"op-log tags" = "white" "op-log tags" = "white"
"op-log head" = { bold = true }
"op-log head id" = "bright blue" "op-log head id" = "bright blue"
"op-log head user" = "bright yellow" "op-log head user" = "bright yellow"
"op-log head time" = "bright cyan" "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<()> { fn write_new_style(&mut self) -> io::Result<()> {
let new_style = self.current_style(); let new_style = self.current_style();
if 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 != self.current_style.bold {
if new_style.bold.unwrap_or_default() { if new_style.bold.unwrap_or_default() {
queue!(self.output, SetAttribute(Attribute::Bold))?; 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> { fn rules_from_config(config: &config::Config) -> HashMap<Vec<String>, Style> {
let mut result = HashMap::new(); let mut result = HashMap::new();
if let Ok(table) = config.get_table("colors") { if let Ok(table) = config.get_table("colors") {
@ -439,14 +416,14 @@ mod tests {
 magenta   magenta 
 cyan   cyan 
 white   white 
 bright black   bright black 
 bright red   bright red 
 bright green   bright green 
 bright yellow   bright yellow 
 bright blue   bright blue 
 bright magenta   bright magenta 
 bright cyan   bright cyan 
 bright white   bright white 
"###); "###);
} }

View file

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

View file

@ -182,7 +182,7 @@ fn test_color_config() {
// Test that --color=always is respected. // Test that --color=always is respected.
let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", "commit_id"]); let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000 o 0000000000000000000000000000000000000000
"###); "###);
@ -193,7 +193,7 @@ color="always""#,
); );
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000 o 0000000000000000000000000000000000000000
"###); "###);
@ -249,7 +249,7 @@ color="always""#,
test_env.add_env_var("NO_COLOR", ""); test_env.add_env_var("NO_COLOR", "");
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22
o 0000000000000000000000000000000000000000 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 // TODO: The color codes shouldn't span the graph lines, and we shouldn't get an
// extra line at the end // extra line at the end
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ single line @ single line
|  | 
o first line o first line
| second line | second line
| third line | third line