mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
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:
parent
e93a347f9e
commit
2a9c37a693
5 changed files with 25 additions and 48 deletions
|
@ -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"
|
||||||
|
|
|
@ -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 {
|
||||||
[38;5;5m magenta [39m
|
[38;5;5m magenta [39m
|
||||||
[38;5;6m cyan [39m
|
[38;5;6m cyan [39m
|
||||||
[38;5;7m white [39m
|
[38;5;7m white [39m
|
||||||
[1m[38;5;8m bright black [0m[39m
|
[38;5;8m bright black [39m
|
||||||
[1m[38;5;9m bright red [0m[39m
|
[38;5;9m bright red [39m
|
||||||
[1m[38;5;10m bright green [0m[39m
|
[38;5;10m bright green [39m
|
||||||
[1m[38;5;11m bright yellow [0m[39m
|
[38;5;11m bright yellow [39m
|
||||||
[1m[38;5;12m bright blue [0m[39m
|
[38;5;12m bright blue [39m
|
||||||
[1m[38;5;13m bright magenta [0m[39m
|
[38;5;13m bright magenta [39m
|
||||||
[1m[38;5;14m bright cyan [0m[39m
|
[38;5;14m bright cyan [39m
|
||||||
[1m[38;5;15m bright white [0m[39m
|
[38;5;15m bright white [39m
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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###"
|
||||||
@ [1m[38;5;13mffdaa62087a2[0m[39m [1m[38;5;11mtest.user@example.com[0m[39m [1m[38;5;14m2001-02-03 04:05:09.000 +07:00[0m[39m [1m[38;5;13mmy-branch[0m[39m [1m[38;5;12m9de54178d59d[0m[39m
|
@ [1m[38;5;13mffdaa62087a2[39m [38;5;11mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;13mmy-branch[39m [38;5;12m9de54178d59d[39m
|
||||||
| [1m[38;5;15mdescription 1[0m[39m
|
| [38;5;15mdescription 1[39m
|
||||||
|
| [0m
|
||||||
o [38;5;5m9a45c67d3e96[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4291e264ae97[39m
|
o [38;5;5m9a45c67d3e96[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4291e264ae97[39m
|
||||||
| add a file
|
| add a file
|
||||||
o [38;5;5m000000000000[39m [38;5;3m[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
o [38;5;5m000000000000[39m [38;5;3m[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
||||||
|
@ -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###"
|
||||||
[1m[38;5;13mffdaa62087a2[0m[39m [1m[38;5;11mtest.user@example.com[0m[39m [1m[38;5;14m2001-02-03 04:05:09.000 +07:00[0m[39m [1m[38;5;13mmy-branch[0m[39m [1m[38;5;12m9de54178d59d[0m[39m
|
[1m[38;5;13mffdaa62087a2[39m [38;5;11mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;13mmy-branch[39m [38;5;12m9de54178d59d[39m
|
||||||
[1m[38;5;15mdescription 1[0m[39m
|
[38;5;15mdescription 1[39m
|
||||||
[38;5;5m9a45c67d3e96[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4291e264ae97[39m
|
[0m[38;5;5m9a45c67d3e96[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4291e264ae97[39m
|
||||||
add a file
|
add a file
|
||||||
[38;5;5m000000000000[39m [38;5;3m[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
[38;5;5m000000000000[39m [38;5;3m[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
||||||
(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 [38;5;1m9a45c67d3e96??[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:10.000 +07:00[39m [38;5;4m8979953d4c67[39m
|
o [38;5;1m9a45c67d3e96??[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:10.000 +07:00[39m [38;5;4m8979953d4c67[39m
|
||||||
| description 2
|
| description 2
|
||||||
| @ [1m[38;5;9m9a45c67d3e96??[0m[39m [1m[38;5;11mtest.user@example.com[0m[39m [1m[38;5;14m2001-02-03 04:05:08.000 +07:00[0m[39m [1m[38;5;12m7a17d52e633c[0m[39m
|
| @ [1m[38;5;9m9a45c67d3e96??[39m [38;5;11mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:08.000 +07:00[39m [38;5;12m7a17d52e633c[39m
|
||||||
|/ [1m[38;5;15mdescription 1[0m[39m
|
|/ [38;5;15mdescription 1[39m
|
||||||
|
| [0m
|
||||||
o [38;5;5m000000000000[39m [38;5;3m[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
o [38;5;5m000000000000[39m [38;5;3m[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
||||||
(no description set)
|
(no description set)
|
||||||
"###);
|
"###);
|
||||||
|
|
|
@ -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###"
|
||||||
@ [1m[38;5;12m230dd059e1b059aefc0da06a2e5a7dbf22362f22[0m[39m
|
@ [1m[38;5;12m230dd059e1b059aefc0da06a2e5a7dbf22362f22[39m[0m
|
||||||
o [38;5;4m0000000000000000000000000000000000000000[39m
|
o [38;5;4m0000000000000000000000000000000000000000[39m
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
@ -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###"
|
||||||
@ [1m[38;5;12m230dd059e1b059aefc0da06a2e5a7dbf22362f22[0m[39m
|
@ [1m[38;5;12m230dd059e1b059aefc0da06a2e5a7dbf22362f22[39m[0m
|
||||||
o [38;5;4m0000000000000000000000000000000000000000[39m
|
o [38;5;4m0000000000000000000000000000000000000000[39m
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
@ -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###"
|
||||||
@ [1m[38;5;12m230dd059e1b059aefc0da06a2e5a7dbf22362f22[0m[39m
|
@ [1m[38;5;12m230dd059e1b059aefc0da06a2e5a7dbf22362f22[39m[0m
|
||||||
o [38;5;4m0000000000000000000000000000000000000000[39m
|
o [38;5;4m0000000000000000000000000000000000000000[39m
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
|
|
@ -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###"
|
||||||
@ [38;5;2msingle line
|
@ [1m[38;5;2msingle line
|
||||||
| [39m
|
| [39m[0m
|
||||||
o [38;5;1mfirst line
|
o [38;5;1mfirst line
|
||||||
| second line
|
| second line
|
||||||
| third line
|
| third line
|
||||||
|
|
Loading…
Reference in a new issue