aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-05-19 18:28:07 +0100
committerNerdyPepper <[email protected]>2019-05-19 18:28:07 +0100
commit2589f9cfa100426d45b759a0a55a10f2b7a2835e (patch)
treea104d4b2a39dfdad768451b1ec0d94aaeeee69e6
parent20ebf3663c20200ecc47bb0737ea53407e51682d (diff)
experiment colored outputs
-rw-r--r--src/main.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index b4972e3..8bacacb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
1use std::env; 1use std::env;
2use tico::tico; 2use tico::tico;
3use git2::{ Repository, Status }; 3use git2::{ Repository, Status };
4use colored::*;
4 5
5fn main() { 6fn main() {
6 println!("{:?}", env::var("GIT_DIRTY")); 7 println!("{:?}", env::var("GIT_DIRTY"));
@@ -11,8 +12,8 @@ fn main() {
11 }, 12 },
12 None => ("".into(), "".into()) 13 None => ("".into(), "".into())
13 }; 14 };
14 println!(" {} {}", branch, status); 15 println!(" {} {}", branch.green(), status.dimmed());
15 println!("{}", prompt_char()); 16 print!("{}", prompt_char());
16} 17}
17 18
18fn cwd() -> String { 19fn cwd() -> String {
@@ -25,18 +26,18 @@ fn cwd() -> String {
25 } 26 }
26} 27}
27 28
28fn prompt_char() -> String { 29fn prompt_char() -> colored::ColoredString {
29 let user_char = env::var("PROMPT_CHAR").unwrap_or("$ ".into()); 30 let user_char = env::var("PROMPT_CHAR").unwrap_or("$ ".into());
30 let root_char = env::var("PROMPT_CHAR_ROOT").unwrap_or("# ".into()); 31 let root_char = env::var("PROMPT_CHAR_ROOT").unwrap_or("# ".into());
31 32
32 let euid = unsafe { libc::geteuid() }; 33 let euid = unsafe { libc::geteuid() };
33 match euid { 34 match euid {
34 0 => return root_char, 35 0 => return root_char.red(),
35 _ => return user_char 36 _ => return user_char.green()
36 } 37 }
37} 38}
38 39
39fn vcs_status() -> Option<(String, String)> { 40fn vcs_status() -> Option<(colored::ColoredString, String)> {
40 let current_dir = env::var("PWD").unwrap(); 41 let current_dir = env::var("PWD").unwrap();
41 42
42 let repo = match Repository::open(current_dir) { 43 let repo = match Repository::open(current_dir) {
@@ -48,11 +49,11 @@ fn vcs_status() -> Option<(String, String)> {
48 let mut branch; 49 let mut branch;
49 50
50 if reference.is_branch() { 51 if reference.is_branch() {
51 branch = format!("{}", reference.shorthand().unwrap()); 52 branch = format!("{}", reference.shorthand().unwrap()).green();
52 } else { 53 } else {
53 let commit = reference.peel_to_commit().unwrap(); 54 let commit = reference.peel_to_commit().unwrap();
54 let id = commit.id(); 55 let id = commit.id();
55 branch = format!("{}", id); 56 branch = format!("{}", id).yellow();
56 } 57 }
57 58
58 let mut repo_stat = String::new(); 59 let mut repo_stat = String::new();