diff options
author | Matan Kushner <hello@matchai.me> | 2019-05-01 16:34:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-01 16:34:24 -0400 |
commit | c6ee5c6ac16d360ab1a44d097c91fe9f98f20f85 (patch) | |
tree | e06814175f34e508fbae4de66571e3d0042786e7 /src/modules/character.rs | |
parent | d945b03093cf130bdc702056650f7e8e8869753b (diff) |
Refactor segments into modules (#40)
Diffstat (limited to 'src/modules/character.rs')
-rw-r--r-- | src/modules/character.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/modules/character.rs b/src/modules/character.rs index f624e19f2..2a9334894 100644 --- a/src/modules/character.rs +++ b/src/modules/character.rs @@ -1,8 +1,6 @@ +use super::{Context, Module}; use ansi_term::Color; -use super::Segment; -use crate::context::Context; - /// Creates a segment for the prompt character /// /// The char segment prints an arrow character in a color dependant on the exit- @@ -11,21 +9,22 @@ use crate::context::Context; /// (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> { +pub fn segment(context: &Context) -> Option<Module> { const PROMPT_CHAR: &str = "➜"; - const COLOR_SUCCESS: Color = Color::Green; - const COLOR_FAILURE: Color = Color::Red; + let color_success = Color::Green.bold(); + let color_failure = Color::Red.bold(); - let mut segment = Segment::new("char"); - let arguments = &context.arguments; + let mut module = Module::new("char"); + module.get_prefix().set_value(""); + + let symbol = module.new_segment("symbol", PROMPT_CHAR); + let arguments = &context.arguments; if arguments.value_of("status_code").unwrap() == "0" { - segment.set_style(COLOR_SUCCESS); + symbol.set_style(color_success.bold()); } else { - segment.set_style(COLOR_FAILURE); + symbol.set_style(color_failure.bold()); }; - segment.set_value(PROMPT_CHAR).set_prefix(None); - - Some(segment) + Some(module) } |