aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeo Wilson <[email protected]>2019-06-03 23:42:03 +0100
committerLeo Wilson <[email protected]>2019-06-03 23:42:03 +0100
commit5d45086eb7069057a1b7e9a89aca5fed9e537dfa (patch)
tree1eb2e0cadb3f5835a529a095a075663f450603d2 /src
parent232f224787efd201cc1da4aba4add490c0825c8a (diff)
Fix issue #1 for ZSH in minimal mode
Diffstat (limited to 'src')
-rw-r--r--src/main.rs56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index d7dc687..0603cba 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,29 +15,44 @@ fn main() {
15 .long("minimal") 15 .long("minimal")
16 .help("use minimal variant") 16 .help("use minimal variant")
17 ) 17 )
18 .arg(Arg::with_name("zsh")
19 .short("z")
20 .long("zsh")
21 .help("Use ZSH formatting")
22 )
18 .get_matches(); 23 .get_matches();
19 if matches.is_present("minimal") { 24 if matches.is_present("minimal") {
20 println!("{}", pista_minimal()); 25 println!("{}", pista_minimal(matches.is_present("zsh")));
21 } else { 26 } else {
22 println!("{}", pista()); 27 println!("{}", pista(matches.is_present("zsh")));
23 } 28 }
24} 29}
25 30
26fn pista() -> String { 31fn pista(zsh: bool) -> String {
27 let cwd = cwd::cwd(); 32 let cwd = cwd::cwd();
28 let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); 33 let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into()));
29 let venv = venv::get_name(); 34 let venv = venv::get_name();
30 let prompt_char = prompt_char::get_char(); 35 let prompt_char = prompt_char::get_char();
31 format!("%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ", 36 if zsh {
37 format!("%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ",
38 cwd=cwd,
39 branch=branch,
40 status=status,
41 venv=venv,
42 pchar=prompt_char
43 )
44 } else {
45 format!("{cwd} {branch} {status}\n{venv}{pchar} ",
32 cwd=cwd, 46 cwd=cwd,
33 branch=branch, 47 branch=branch,
34 status=status, 48 status=status,
35 venv=venv, 49 venv=venv,
36 pchar=prompt_char 50 pchar=prompt_char
37 ) 51 )
52 }
38} 53}
39 54
40fn pista_minimal() -> String { 55fn pista_minimal(zsh: bool) -> String {
41 let cwd = cwd::cwd(); 56 let cwd = cwd::cwd();
42 let vcs_tuple = vcs::vcs_status(); 57 let vcs_tuple = vcs::vcs_status();
43 let mut vcs_component = String::new(); 58 let mut vcs_component = String::new();
@@ -48,10 +63,39 @@ fn pista_minimal() -> String {
48 } 63 }
49 let venv = venv::get_name(); 64 let venv = venv::get_name();
50 let prompt_char = prompt_char::get_char(); 65 let prompt_char = prompt_char::get_char();
51 format!("{cwd}{vcs}{venv}{pchar} ", 66 if zsh {
67 let fmt = format!("{cwd}{vcs}{venv}{pchar} ",
68 cwd=cwd,
69 vcs=vcs_component,
70 venv=venv,
71 pchar=prompt_char
72 );
73 let mut ret = String::new();
74 let mut color = false;
75 for ch in fmt.chars() {
76 if color {
77 if ch == 'm' { // colors always end with m
78 ret.push_str("m%}");
79 color = false;
80 } else {
81 ret.push(ch)
82 }
83 } else {
84 if ch == 0x1b_u8.into() { // ESC char, always starts colors
85 ret.push_str(&format!("%{{{esc}", esc=ch));
86 color = true;
87 } else {
88 ret.push(ch);
89 }
90 }
91 }
92 ret
93 } else {
94 format!("{cwd}{vcs}{venv}{pchar} ",
52 cwd=cwd, 95 cwd=cwd,
53 vcs=vcs_component, 96 vcs=vcs_component,
54 venv=venv, 97 venv=venv,
55 pchar=prompt_char 98 pchar=prompt_char
56 ) 99 )
100 }
57} 101}