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:
parent
471af82ebe
commit
a81eabd690
@ -5,16 +5,8 @@ extern crate ansi_term;
|
|||||||
mod modules;
|
mod modules;
|
||||||
mod print;
|
mod print;
|
||||||
|
|
||||||
use ansi_term::Style;
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
|
||||||
pub struct Segment {
|
|
||||||
style: Style,
|
|
||||||
value: String,
|
|
||||||
prefix: Option<Box<Segment>>,
|
|
||||||
suffix: Option<Box<Segment>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = App::new("Starship")
|
let args = App::new("Starship")
|
||||||
.about("The cross-platform prompt for astronauts. ✨🚀")
|
.about("The cross-platform prompt for astronauts. ✨🚀")
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
use crate::Segment;
|
use super::Segment;
|
||||||
use ansi_term::{Color, Style};
|
use ansi_term::{Color, Style};
|
||||||
use clap::ArgMatches;
|
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 {
|
pub fn segment(args: &ArgMatches) -> Segment {
|
||||||
const PROMPT_CHAR: &str = "➜ ";
|
const PROMPT_CHAR: &str = "➜ ";
|
||||||
const COLOR_SUCCESS: Color = Color::Green;
|
const COLOR_SUCCESS: Color = Color::Green;
|
||||||
@ -15,10 +23,9 @@ pub fn segment(args: &ArgMatches) -> Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Segment {
|
Segment {
|
||||||
prefix: None,
|
|
||||||
value: String::from(PROMPT_CHAR),
|
value: String::from(PROMPT_CHAR),
|
||||||
style: Style::from(color),
|
style: Style::from(color),
|
||||||
suffix: None,
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,25 @@
|
|||||||
mod char;
|
mod char;
|
||||||
|
|
||||||
use crate::Segment;
|
|
||||||
use clap::ArgMatches;
|
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 {
|
pub fn handle(module: &str, args: &ArgMatches) -> Segment {
|
||||||
match module {
|
match module {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::modules;
|
use crate::modules;
|
||||||
use crate::Segment;
|
use crate::modules::Segment;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
|
||||||
pub fn prompt(args: ArgMatches) {
|
pub fn prompt(args: ArgMatches) {
|
||||||
|
Loading…
Reference in New Issue
Block a user