Move Segment struct to modules
This commit is contained in:
parent
471af82ebe
commit
a81eabd690
|
@ -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. ✨🚀")
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::modules;
|
||||
use crate::Segment;
|
||||
use crate::modules::Segment;
|
||||
use clap::ArgMatches;
|
||||
|
||||
pub fn prompt(args: ArgMatches) {
|
||||
|
|
Loading…
Reference in New Issue