From 8c0f6a53c5e2522cf74649bb67e645ec63fe33a6 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 4 Mar 2024 18:35:14 +0900 Subject: [PATCH] cli: colorize output of "config list" --- cli/src/commands/config.rs | 2 ++ cli/src/config/colors.toml | 8 ++++++++ cli/src/config/templates.toml | 12 +++++++----- cli/tests/test_config_command.rs | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cli/src/commands/config.rs b/cli/src/commands/config.rs index 639c87eb3..7a4932003 100644 --- a/cli/src/commands/config.rs +++ b/cli/src/commands/config.rs @@ -226,6 +226,7 @@ pub(crate) fn cmd_config_list( ui.request_pager(); let mut formatter = ui.stdout_formatter(); + formatter.push_label("config_list")?; let name_path = args .name .as_ref() @@ -251,6 +252,7 @@ pub(crate) fn cmd_config_list( template.format(&annotated, formatter.as_mut())?; wrote_values = true; } + formatter.pop_label()?; drop(formatter); if !wrote_values { // Note to stderr explaining why output is empty. diff --git a/cli/src/config/colors.toml b/cli/src/config/colors.toml index 08923ccf2..66fea8540 100644 --- a/cli/src/config/colors.toml +++ b/cli/src/config/colors.toml @@ -59,6 +59,13 @@ "working_copy placeholder" = "bright red" "working_copy description placeholder" = "yellow" "working_copy empty description placeholder" = "bright green" + +"config_list name" = "green" +"config_list value" = "yellow" +"config_list overridden" = "bright black" +"config_list overridden name" = "bright black" +"config_list overridden value" = "bright black" + "diff header" = "yellow" "diff empty" = "cyan" "diff binary" = "cyan" @@ -67,6 +74,7 @@ "diff removed" = "red" "diff added" = "green" "diff modified" = "cyan" + "op_log id" = "blue" "op_log user" = "yellow" "op_log time" = "cyan" diff --git a/cli/src/config/templates.toml b/cli/src/config/templates.toml index 2ad29d193..b75f506fb 100644 --- a/cli/src/config/templates.toml +++ b/cli/src/config/templates.toml @@ -25,11 +25,13 @@ separate(" ", ''' config_list = ''' -concat( - if(overridden, "# "), - name, - "=", - value, +label(if(overridden, "overridden"), + concat( + if(overridden, "# "), + name, + "=", + value, + ), ) ++ "\n" ''' diff --git a/cli/tests/test_config_command.rs b/cli/tests/test_config_command.rs index e02869206..8b1842ea5 100644 --- a/cli/tests/test_config_command.rs +++ b/cli/tests/test_config_command.rs @@ -254,6 +254,21 @@ fn test_config_layer_override_default() { # merge-tools.vimdiff.program="repo" merge-tools.vimdiff.program="command-arg" "###); + + let stdout = test_env.jj_cmd_success( + &repo_path, + &[ + "config", + "list", + "--color=always", + config_key, + "--include-overridden", + ], + ); + insta::assert_snapshot!(stdout, @r###" + # merge-tools.vimdiff.program="user" + merge-tools.vimdiff.program="repo" + "###); } #[test]