diff options
author | Kevin Song <chipbuster@users.noreply.github.com> | 2019-09-07 19:33:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-07 19:33:06 -0500 |
commit | 9721666d331ddfd7a04bbb434cccf38b44701b00 (patch) | |
tree | 8edb32e1cebc6951451953a311cd9cfb4447712d /src/modules/character.rs | |
parent | 3e5cac98522feca856867e32cf3df52ff0285c62 (diff) |
feat: Add the ability to configure per-module color styles (#285)
Add parsing logic, config support, docs, and integration with other modules
for custom styling of each module.
Diffstat (limited to 'src/modules/character.rs')
-rw-r--r-- | src/modules/character.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs index 9c4d7e982..704fe5c9f 100644 --- a/src/modules/character.rs +++ b/src/modules/character.rs @@ -5,10 +5,10 @@ use ansi_term::Color; /// /// The character segment prints an arrow character in a color dependant on the exit- /// code of the last executed command: -/// - If the exit-code was "0", the arrow will be formatted with `COLOR_SUCCESS` +/// - If the exit-code was "0", the arrow will be formatted with `style_success` /// (green by default) /// - If the exit-code was anything else, the arrow will be formatted with -/// `COLOR_FAILURE` (red by default) +/// `style_failure` (red by default) pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { const SUCCESS_CHAR: &str = "❯"; const FAILURE_CHAR: &str = "✖"; @@ -20,12 +20,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { const ASSUMED_MODE: ShellEditMode = ShellEditMode::Insert; // TODO: extend config to more modes - let color_success = Color::Green.bold(); - let color_failure = Color::Red.bold(); - let mut module = context.new_module("character")?; module.get_prefix().set_value(""); + let style_success = module + .config_value_style("style_success") + .unwrap_or_else(|| Color::Green.bold()); + let style_failure = module + .config_value_style("style_failure") + .unwrap_or_else(|| Color::Red.bold()); + let arguments = &context.arguments; let use_symbol = module .config_value_bool("use_symbol_for_status") @@ -56,9 +60,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { }; if exit_success { - symbol.set_style(color_success.bold()); + symbol.set_style(style_success); } else { - symbol.set_style(color_failure.bold()); + symbol.set_style(style_failure); }; Some(module) |