summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs8
-rw-r--r--src/modules/char.rs13
-rw-r--r--src/modules/mod.rs20
-rw-r--r--src/print.rs2
4 files changed, 30 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 7cbe7d225..f1de02bbe 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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. ✨🚀")
diff --git a/src/modules/char.rs b/src/modules/char.rs
index b5d6183af..93d8df692 100644
--- a/src/modules/char.rs
+++ b/src/modules/char.rs
@@ -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()
}
}
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index 52474cbcf..869a82c2c 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -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 {
diff --git a/src/print.rs b/src/print.rs
index 1fc6e535e..a74655aa4 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -1,5 +1,5 @@
use crate::modules;
-use crate::Segment;
+use crate::modules::Segment;
use clap::ArgMatches;
pub fn prompt(args: ArgMatches) {