From 41ee54933bd2820b1ba97726514f785f1ac73824 Mon Sep 17 00:00:00 2001 From: Matan Kushner Date: Tue, 2 Apr 2019 00:45:49 -0400 Subject: [PATCH] Start working on char color for status --- Cargo.lock | 1 + Cargo.toml | 1 + src/char.rs | 20 ++++++++++++++++++++ src/main.rs | 9 ++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/char.rs diff --git a/Cargo.lock b/Cargo.lock index ba27c589..317dfe25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -57,6 +57,7 @@ dependencies = [ name = "starship" version = "0.1.0" dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 2300789c..2f7fbeaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2018" [dependencies] clap = "2.32.0" +ansi_term = "0.11.0" diff --git a/src/char.rs b/src/char.rs new file mode 100644 index 00000000..7d0998b4 --- /dev/null +++ b/src/char.rs @@ -0,0 +1,20 @@ +use std::env; +use ansi_term::Color; + +pub fn display() { + let PROMPT_CHAR = "➜ "; + let COLOR_SUCCESS = Color::Green; + let COLOR_FAILURE = Color::Red; + + let color = match env::var_os("status") { + None | "0" => COLOR_SUCCESS, + _ => COLOR_FAILURE + }; + + // let color = match env::var("status") { + // Ok("0") | _ => COLOR_SUCCESS, + // Ok("1") => COLOR_FAILURE + // }; + + print!("{}", color.paint(PROMPT_CHAR)); +} diff --git a/src/main.rs b/src/main.rs index 17c57862..8a6cd5fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,20 @@ #[macro_use] extern crate clap; use clap::App; +use std::io; + +mod char; fn main() { - let matches = App::new("Starship") + App::new("Starship") .about("The cross-platform prompt for astronauts. ✨🚀") // pull the version number from Cargo.toml .version(crate_version!()) // pull the authors from Cargo.toml .author(crate_authors!()) .get_matches(); + + prompt::char(); + // let stdout = io::stdout(); + // let mut handle = io::BufWriter::new(stdout); }