From 4b147b4656135a04d2a4c2347e59f04d4f388d26 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 3 Feb 2020 19:06:27 +0530 Subject: new links, rustfmt --- readme.md | 2 +- src/main.rs | 86 +++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/readme.md b/readme.md index cc0d2c6..2524932 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ > a simple {bash, zsh} prompt for programmers -![pista.png](https://files.nerdypepper.tech/GZ.png) +![pista.png](https://u.peppe.rs/GZ.png) ### features diff --git a/src/main.rs b/src/main.rs index 3096635..b839325 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod prompt_char; mod vcs; mod venv; -use clap::{Arg, App}; +use clap::{App, Arg}; use colored::*; fn main() { @@ -11,15 +11,17 @@ fn main() { .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") + .arg( + Arg::with_name("minimal") + .short("m") + .long("minimal") + .help("use minimal variant"), ) - .arg(Arg::with_name("zsh") - .short("z") - .long("zsh") - .help("Use ZSH formatting") + .arg( + Arg::with_name("zsh") + .short("z") + .long("zsh") + .help("Use ZSH formatting"), ) .get_matches(); if matches.is_present("minimal") { @@ -32,34 +34,36 @@ fn main() { fn pista(zsh: bool) -> String { let cwd = match cwd::cwd() { Some(c) => c, - None => "[directory does not exist]".color("red") + None => "[directory does not exist]".color("red"), }; let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); let venv = venv::get_name(); let prompt_char = prompt_char::get_char(); if zsh { - format!("%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ", - cwd=cwd, - branch=branch, - status=status, - venv=venv, - pchar=prompt_char - ) + format!( + "%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ", + cwd = cwd, + branch = branch, + status = status, + venv = venv, + pchar = prompt_char + ) } else { - format!("{cwd} {branch} {status}\n{venv}{pchar} ", - cwd=cwd, - branch=branch, - status=status, - venv=venv, - pchar=prompt_char - ) + format!( + "{cwd} {branch} {status}\n{venv}{pchar} ", + cwd = cwd, + branch = branch, + status = status, + venv = venv, + pchar = prompt_char + ) } } fn pista_minimal(zsh: bool) -> String { let cwd = match cwd::cwd() { Some(c) => c, - None => "[directory does not exist]".color("red") + None => "[directory does not exist]".color("red"), }; let vcs_tuple = vcs::vcs_status(); let mut vcs_component = String::new(); @@ -71,25 +75,28 @@ fn pista_minimal(zsh: bool) -> String { let venv = venv::get_name(); let prompt_char = prompt_char::get_char(); if zsh { - let fmt = format!("{cwd}{vcs}{venv}{pchar} ", - cwd=cwd, - vcs=vcs_component, - venv=venv, - pchar=prompt_char + let fmt = format!( + "{cwd}{vcs}{venv}{pchar} ", + cwd = cwd, + vcs = vcs_component, + venv = venv, + pchar = prompt_char ); let mut ret = String::new(); let mut color = false; for ch in fmt.chars() { if color { - if ch == 'm' { // colors always end with m + if ch == 'm' { + // colors always end with m ret.push_str("m%}"); color = false; } else { ret.push(ch) } } else { - if ch == 0x1b_u8.into() { // ESC char, always starts colors - ret.push_str(&format!("%{{{esc}", esc=ch)); + if ch == 0x1b_u8.into() { + // ESC char, always starts colors + ret.push_str(&format!("%{{{esc}", esc = ch)); color = true; } else { ret.push(ch); @@ -98,11 +105,12 @@ fn pista_minimal(zsh: bool) -> String { } ret } else { - format!("{cwd}{vcs}{venv}{pchar} ", - cwd=cwd, - vcs=vcs_component, - venv=venv, - pchar=prompt_char - ) + format!( + "{cwd}{vcs}{venv}{pchar} ", + cwd = cwd, + vcs = vcs_component, + venv = venv, + pchar = prompt_char + ) } } -- cgit v1.2.3