From 5cb3807b2630076beda0d73d033f6af2efa665f9 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 23 Dec 2022 07:06:24 -0800 Subject: [PATCH] colors: move defaults from source to file --- src/config.rs | 4 ++ src/config/colors.toml | 54 ++++++++++++++++++++ src/formatter.rs | 113 ----------------------------------------- 3 files changed, 58 insertions(+), 113 deletions(-) create mode 100644 src/config/colors.toml diff --git a/src/config.rs b/src/config.rs index 8167d5e1c0..7ddf20b7e0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -76,6 +76,10 @@ pub fn default_config() -> config::Config { // Syntax error in default config isn't a user error. That's why defaults are // loaded by separate builder. config::Config::builder() + .add_source(config::File::from_str( + include_str!("config/colors.toml"), + config::FileFormat::Toml, + )) .add_source(config::File::from_str( include_str!("config/merge_tools.toml"), config::FileFormat::Toml, diff --git a/src/config/colors.toml b/src/config/colors.toml new file mode 100644 index 0000000000..48da0d5af7 --- /dev/null +++ b/src/config/colors.toml @@ -0,0 +1,54 @@ +[colors] +"error" = "red" +"warning" = "yellow" +"hint" = "blue" + +"commit_id" = "blue" +"change_id" = "magenta" +"author" = "yellow" +"author timestamp" = "cyan" +"committer" = "yellow" +"committer timestamp" = "cyan" +"working_copies" = "magenta" +"branch" = "magenta" +"branches" = "magenta" +"tags" = "magenta" +"git_refs" = "magenta" +"git_head" = "magenta" +"divergent" = "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 commit_id" = "bright blue" +"working_copy change_id" = "bright magenta" +"working_copy author" = "bright yellow" +"working_copy author timestamp" = "bright cyan" +"working_copy committer" = "bright yellow" +"working_copy committer timestamp" = "bright cyan" +"working_copy working_copies" = "bright magenta" +"working_copy branch" = "bright magenta" +"working_copy branches" = "bright magenta" +"working_copy tags" = "bright magenta" +"working_copy git_refs" = "bright magenta" +"working_copy divergent" = "bright red" +"working_copy conflict" = "bright red" +"working_copy description" = "bright white" +"diff header" = "yellow" +"diff file_header" = "bright white" +"diff hunk_header" = "cyan" +"diff removed" = "red" +"diff added" = "green" +"diff modified" = "cyan" +"op-log id" = "blue" +"op-log user" = "yellow" +"op-log time" = "cyan" +"op-log tags" = "white" +"op-log head id" = "bright blue" +"op-log head user" = "bright yellow" +"op-log head time" = "bright cyan" +"op-log head description" = "bright white" +"op-log head tags" = "bright white" diff --git a/src/formatter.rs b/src/formatter.rs index 25751f1fe1..3b9a927cdf 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -135,119 +135,6 @@ pub struct ColorFormatter { fn config_colors(user_settings: &UserSettings) -> HashMap { let mut result = HashMap::new(); - result.insert(String::from("error"), String::from("red")); - result.insert(String::from("warning"), String::from("yellow")); - result.insert(String::from("hint"), String::from("blue")); - - result.insert(String::from("commit_id"), String::from("blue")); - result.insert(String::from("change_id"), String::from("magenta")); - result.insert(String::from("author"), String::from("yellow")); - result.insert(String::from("author timestamp"), String::from("cyan")); - result.insert(String::from("committer"), String::from("yellow")); - result.insert(String::from("committer timestamp"), String::from("cyan")); - result.insert(String::from("working_copies"), String::from("magenta")); - result.insert(String::from("branch"), String::from("magenta")); - result.insert(String::from("branches"), String::from("magenta")); - result.insert(String::from("tags"), String::from("magenta")); - result.insert(String::from("git_refs"), String::from("magenta")); - result.insert(String::from("git_head"), String::from("magenta")); - result.insert(String::from("divergent"), String::from("red")); - result.insert(String::from("conflict"), String::from("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.) - result.insert( - String::from("working_copy commit_id"), - String::from("bright blue"), - ); - result.insert( - String::from("working_copy change_id"), - String::from("bright magenta"), - ); - result.insert( - String::from("working_copy author"), - String::from("bright yellow"), - ); - result.insert( - String::from("working_copy author timestamp"), - String::from("bright cyan"), - ); - result.insert( - String::from("working_copy committer"), - String::from("bright yellow"), - ); - result.insert( - String::from("working_copy committer timestamp"), - String::from("bright cyan"), - ); - result.insert( - String::from("working_copy working_copies"), - String::from("bright magenta"), - ); - result.insert( - String::from("working_copy branch"), - String::from("bright magenta"), - ); - result.insert( - String::from("working_copy branches"), - String::from("bright magenta"), - ); - result.insert( - String::from("working_copy tags"), - String::from("bright magenta"), - ); - result.insert( - String::from("working_copy git_refs"), - String::from("bright magenta"), - ); - result.insert( - String::from("working_copy divergent"), - String::from("bright red"), - ); - result.insert( - String::from("working_copy conflict"), - String::from("bright red"), - ); - result.insert( - String::from("working_copy description"), - String::from("bright white"), - ); - - result.insert(String::from("diff header"), String::from("yellow")); - result.insert( - String::from("diff file_header"), - String::from("bright white"), - ); - result.insert(String::from("diff hunk_header"), String::from("cyan")); - result.insert(String::from("diff removed"), String::from("red")); - result.insert(String::from("diff added"), String::from("green")); - result.insert(String::from("diff modified"), String::from("cyan")); - - result.insert(String::from("op-log id"), String::from("blue")); - result.insert(String::from("op-log user"), String::from("yellow")); - result.insert(String::from("op-log time"), String::from("cyan")); - result.insert(String::from("op-log tags"), String::from("white")); - - result.insert(String::from("op-log head id"), String::from("bright blue")); - result.insert( - String::from("op-log head user"), - String::from("bright yellow"), - ); - result.insert( - String::from("op-log head time"), - String::from("bright cyan"), - ); - result.insert( - String::from("op-log head description"), - String::from("bright white"), - ); - result.insert( - String::from("op-log head tags"), - String::from("bright white"), - ); - if let Ok(table) = user_settings.config().get_table("colors") { for (key, value) in table { result.insert(key, value.to_string());