1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-16 10:05:13 +00:00
starship/src/modules/character.rs

32 lines
968 B
Rust
Raw Normal View History

2019-04-12 23:11:40 +00:00
use ansi_term::Color;
use super::Segment;
use crate::context::Context;
2019-04-04 00:14:26 +00:00
2019-04-04 18:18:15 +00:00
/// Creates a segment for the prompt character
2019-04-05 01:35:24 +00:00
///
2019-04-04 16:18:02 +00:00
/// The char 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`
/// (green by default)
/// - If the exit-code was anything else, the arrow will be formatted with
/// `COLOR_FAILURE` (red by default)
pub fn segment(context: &Context) -> Option<Segment> {
2019-04-10 13:22:11 +00:00
const PROMPT_CHAR: &str = "";
2019-04-04 00:14:26 +00:00
const COLOR_SUCCESS: Color = Color::Green;
const COLOR_FAILURE: Color = Color::Red;
2019-04-12 23:11:40 +00:00
let mut segment = Segment::new("char");
let arguments = &context.arguments;
2019-04-12 21:49:20 +00:00
if arguments.value_of("status_code").unwrap() == "0" {
2019-04-12 21:49:20 +00:00
segment.set_style(COLOR_SUCCESS);
2019-04-04 00:14:26 +00:00
} else {
2019-04-12 22:12:29 +00:00
segment.set_style(COLOR_FAILURE);
2019-04-08 03:28:38 +00:00
};
2019-04-04 00:14:26 +00:00
2019-04-13 03:06:48 +00:00
segment.set_value(PROMPT_CHAR).set_prefix(None);
Some(segment)
2019-04-04 00:14:26 +00:00
}