summaryrefslogtreecommitdiffstats
path: root/src/modules/character.rs
diff options
context:
space:
mode:
authorKevin Song <chipbuster@users.noreply.github.com>2019-08-10 14:30:30 -0700
committerMatan Kushner <hello@matchai.me>2019-08-10 17:30:30 -0400
commit39598ec691387637e144799f2d8a983148fd0a57 (patch)
tree7843949bab665779b4a27e042e4d858628eaa5da /src/modules/character.rs
parent994a865d4da6e67326e1f19094a507b6b226f225 (diff)
feat: Add configuration to change the character for non-zero sta… (#133)
Prompt can now switch characters in addition to switching character color. Add configuration options in so that users can do either, both, or neither.
Diffstat (limited to 'src/modules/character.rs')
-rw-r--r--src/modules/character.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs
index 6d6a4a1e1..7946cff49 100644
--- a/src/modules/character.rs
+++ b/src/modules/character.rs
@@ -10,17 +10,29 @@ use ansi_term::Color;
/// - If the exit-code was anything else, the arrow will be formatted with
/// `COLOR_FAILURE` (red by default)
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- const PROMPT_CHAR: &str = "➜";
+ const SUCCESS_CHAR: &str = "➜";
+ const FAILURE_CHAR: &str = "✖";
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 symbol = module.new_segment("symbol", PROMPT_CHAR);
-
let arguments = &context.arguments;
- if arguments.value_of("status_code").unwrap_or("0") == "0" {
+ 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";
+
+ /* 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 {
+ module.new_segment("symbol", SUCCESS_CHAR)
+ };
+
+ if exit_success {
symbol.set_style(color_success.bold());
} else {
symbol.set_style(color_failure.bold());