Files
starship/src/modules/character.rs
T

31 lines
1.0 KiB
Rust
Raw Normal View History

2019-05-01 16:34:24 -04:00
use super::{Context, Module};
2019-04-12 19:11:40 -04:00
use ansi_term::Color;
2019-04-19 16:57:14 -04:00
2019-07-19 16:18:52 -04:00
/// Creates a module for the prompt character
2019-04-04 21:35:24 -04:00
///
2019-07-19 16:18:52 -04:00
/// The character segment prints an arrow character in a color dependant on the exit-
2019-04-04 12:18:02 -04:00
/// code of the last executed command:
/// - If the exit-code was "0", the arrow will be formatted with `COLOR_SUCCESS`
/// (green by default)
/// - 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>> {
2019-04-10 09:22:11 -04:00
const PROMPT_CHAR: &str = "";
2019-05-01 16:34:24 -04:00
let color_success = Color::Green.bold();
let color_failure = Color::Red.bold();
2019-04-03 20:14:26 -04:00
2019-07-19 16:18:52 -04:00
let mut module = context.new_module("character")?;
2019-05-01 16:34:24 -04:00
module.get_prefix().set_value("");
let symbol = module.new_segment("symbol", PROMPT_CHAR);
2019-04-12 17:49:20 -04:00
2019-05-01 16:34:24 -04:00
let arguments = &context.arguments;
2019-06-06 13:18:00 +01:00
if arguments.value_of("status_code").unwrap_or("0") == "0" {
2019-05-01 16:34:24 -04:00
symbol.set_style(color_success.bold());
2019-04-03 20:14:26 -04:00
} else {
2019-05-01 16:34:24 -04:00
symbol.set_style(color_failure.bold());
2019-04-07 23:28:38 -04:00
};
2019-04-03 20:14:26 -04:00
2019-05-01 16:34:24 -04:00
Some(module)
2019-04-03 20:14:26 -04:00
}