blob: b5d6183afdfef84d5c31e51718efee9663d9ac2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use crate::Segment;
use ansi_term::{Color, Style};
use clap::ArgMatches;
pub fn segment(args: &ArgMatches) -> Segment {
const PROMPT_CHAR: &str = "➜ ";
const COLOR_SUCCESS: Color = Color::Green;
const COLOR_FAILURE: Color = Color::Red;
let color;
if args.value_of("status_code").unwrap() == "0" {
color = COLOR_SUCCESS;
} else {
color = COLOR_FAILURE;
}
Segment {
prefix: None,
value: String::from(PROMPT_CHAR),
style: Style::from(color),
suffix: None,
}
}
#[cfg(test)]
mod tests {
use super::*;
use clap::{App, Arg};
#[test]
fn char_section_success_status() {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let segment = segment(&args);
assert_eq!(segment.style, Style::from(Color::Green));
}
#[test]
fn char_section_failure_status() {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "1"]);
let segment = segment(&args);
assert_eq!(segment.style, Style::from(Color::Red));
}
}
|