1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-24 13:47:38 +00:00

Move Segment struct to modules

This commit is contained in:
Matan Kushner 2019-04-04 12:18:02 -04:00
parent 471af82ebe
commit a81eabd690
No known key found for this signature in database
GPG Key ID: 4B98C3A8949CA8A4
4 changed files with 30 additions and 13 deletions

View File

@ -5,16 +5,8 @@ extern crate ansi_term;
mod modules;
mod print;
use ansi_term::Style;
use clap::{App, Arg};
pub struct Segment {
style: Style,
value: String,
prefix: Option<Box<Segment>>,
suffix: Option<Box<Segment>>,
}
fn main() {
let args = App::new("Starship")
.about("The cross-platform prompt for astronauts. ✨🚀")

View File

@ -1,7 +1,15 @@
use crate::Segment;
use super::Segment;
use ansi_term::{Color, Style};
use clap::ArgMatches;
/// Prints the prompt character
///
/// 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(args: &ArgMatches) -> Segment {
const PROMPT_CHAR: &str = "";
const COLOR_SUCCESS: Color = Color::Green;
@ -15,10 +23,9 @@ pub fn segment(args: &ArgMatches) -> Segment {
}
Segment {
prefix: None,
value: String::from(PROMPT_CHAR),
style: Style::from(color),
suffix: None,
..Default::default()
}
}

View File

@ -1,7 +1,25 @@
mod char;
use crate::Segment;
use clap::ArgMatches;
use ansi_term::Style;
pub struct Segment {
pub style: Style,
pub value: String,
pub prefix: Option<Box<Segment>>,
pub suffix: Option<Box<Segment>>,
}
impl Default for Segment {
fn default() -> Segment {
Segment {
style: Style::default(),
value: String::from(""),
prefix: None,
suffix: None
}
}
}
pub fn handle(module: &str, args: &ArgMatches) -> Segment {
match module {

View File

@ -1,5 +1,5 @@
use crate::modules;
use crate::Segment;
use crate::modules::Segment;
use clap::ArgMatches;
pub fn prompt(args: ArgMatches) {