aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: d7dc687947ba34c5ef688c0724e4457d4d88f911 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
mod cwd;
mod prompt_char;
mod vcs;
mod venv;

use clap::{Arg, App};

fn main() {
    let matches = App::new("Pista")
        .version(env!("CARGO_PKG_VERSION"))
        .author(env!("CARGO_PKG_AUTHORS"))
        .about(env!("CARGO_PKG_DESCRIPTION"))
        .arg(Arg::with_name("minimal")
             .short("m")
             .long("minimal")
             .help("use minimal variant")
        )
        .get_matches();
    if matches.is_present("minimal") {
        println!("{}", pista_minimal());
    } else {
        println!("{}", pista());
    }
}

fn pista() -> String {
    let cwd = cwd::cwd();
    let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into()));
    let venv = venv::get_name();
    let prompt_char = prompt_char::get_char();
    format!("%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ",
            cwd=cwd,
            branch=branch,
            status=status,
            venv=venv,
            pchar=prompt_char
            )
}

fn pista_minimal() -> String {
    let cwd = cwd::cwd();
    let vcs_tuple = vcs::vcs_status();
    let mut vcs_component = String::new();
    if let Some((branch, status)) = vcs_tuple {
        vcs_component = format!(" [{} {}] ", branch, status);
    } else {
        vcs_component.push(' ');
    }
    let venv = venv::get_name();
    let prompt_char = prompt_char::get_char();
    format!("{cwd}{vcs}{venv}{pchar} ",
            cwd=cwd,
            vcs=vcs_component,
            venv=venv,
            pchar=prompt_char
            )
}