summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/module.rs4
-rw-r--r--src/modules/character.rs20
2 files changed, 18 insertions, 6 deletions
diff --git a/src/module.rs b/src/module.rs
index ade5d9e5d..4c5787573 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -44,7 +44,7 @@ impl<'a> Module<'a> {
let mut segment = Segment::new(name);
segment.set_style(self.style);
// Use the provided value unless overwritten by config
- segment.set_value(self.config_value(name).unwrap_or(value));
+ segment.set_value(self.config_value_str(name).unwrap_or(value));
self.segments.push(segment);
self.segments.last_mut().unwrap()
@@ -96,7 +96,7 @@ impl<'a> Module<'a> {
}
/// Get a module's config value as a string
- fn config_value(&self, key: &str) -> Option<&str> {
+ pub fn config_value_str(&self, key: &str) -> Option<&str> {
self.config.and_then(|config| config.get_as_str(key))
}
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());