colors: move defaults from source to file

This commit is contained in:
Martin von Zweigbergk 2022-12-23 07:06:24 -08:00 committed by Martin von Zweigbergk
parent 6514ab2e3a
commit 5cb3807b26
3 changed files with 58 additions and 113 deletions

View file

@ -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,

54
src/config/colors.toml Normal file
View file

@ -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"

View file

@ -135,119 +135,6 @@ pub struct ColorFormatter<W> {
fn config_colors(user_settings: &UserSettings) -> HashMap<String, String> {
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());