diff options
author | Zhenhui Xie <xiezh0831@126.com> | 2019-09-30 20:10:35 +0800 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-09-30 21:10:35 +0900 |
commit | dd0b1a1aa2c36bf2df4db9c11a6517a018ffa100 (patch) | |
tree | e2bb1b1bc6b60cb23848af9c625d21575250ecf0 /src/modules/character.rs | |
parent | 9e9eb6a8ef87f7b93dc07e0cf068ccb1a6ce588c (diff) |
refactor: Refactoring config (#383)
This PR refactors config and puts configuration files for all modules in `configs/`.
Diffstat (limited to 'src/modules/character.rs')
-rw-r--r-- | src/modules/character.rs | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs deleted file mode 100644 index 9385e53c9..000000000 --- a/src/modules/character.rs +++ /dev/null @@ -1,69 +0,0 @@ -use super::{Context, Module}; -use ansi_term::Color; - -/// Creates a module for the prompt character -/// -/// 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 `style_success` -/// (green by default) -/// - If the exit-code was anything else, the arrow will be formatted with -/// `style_failure` (red by default) -pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { - const SUCCESS_CHAR: &str = "❯"; - const FAILURE_CHAR: &str = "✖"; - const VICMD_CHAR: &str = "❮"; - enum ShellEditMode { - Normal, - Insert, - }; - const ASSUMED_MODE: ShellEditMode = ShellEditMode::Insert; - // TODO: extend config to more modes - - 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") - .unwrap_or(false); - let exit_success = arguments.value_of("status_code").unwrap_or("0") == "0"; - let shell = std::env::var("STARSHIP_SHELL").unwrap_or_default(); - let keymap = arguments.value_of("keymap").unwrap_or("viins"); - - // Match shell "keymap" names to normalized vi modes - // NOTE: in vi mode, fish reports normal mode as "default". - // Unfortunately, this is also the name of the non-vi default mode. - // We do some environment detection in src/init.rs to translate. - // The result: in non-vi fish, keymap is always reported as "insert" - let mode = match (shell.as_str(), keymap) { - ("fish", "default") | ("zsh", "vicmd") => ShellEditMode::Normal, - _ => ASSUMED_MODE, - }; - - /* If an error symbol is set in the config, use symbols to indicate - success/failure, in addition to color */ - let symbol = if use_symbol && !exit_success { - module.new_segment("error_symbol", FAILURE_CHAR) - } else { - match mode { - ShellEditMode::Normal => module.new_segment("vicmd_symbol", VICMD_CHAR), - ShellEditMode::Insert => module.new_segment("symbol", SUCCESS_CHAR), - } - }; - - if exit_success { - symbol.set_style(style_success); - } else { - symbol.set_style(style_failure); - }; - - Some(module) -} |