diff --git a/src/indicators/error.rs b/src/indicators/error.rs new file mode 100644 index 0000000..38681df --- /dev/null +++ b/src/indicators/error.rs @@ -0,0 +1,17 @@ +use colored::{ColoredString, Colorize}; + +pub fn err(args: Vec) -> String { + if args.len() > 2 { + args[2].clone() // Error status + } else { + "none".to_string() + } +} + +pub fn err_indicator(err: String) -> ColoredString { + let angle = "❯"; + match err.as_str() { + "0" => angle.truecolor(0, 255, 180), + _ => angle.truecolor(255, 53, 94), + } +} diff --git a/src/git.rs b/src/indicators/git.rs similarity index 100% rename from src/git.rs rename to src/indicators/git.rs diff --git a/src/indicators/shell.rs b/src/indicators/shell.rs new file mode 100644 index 0000000..513ea28 --- /dev/null +++ b/src/indicators/shell.rs @@ -0,0 +1,20 @@ +pub fn get_shell_char(shell: &str) -> String { + let shell_char = match shell { + "bash" | "/bin/bash" | "/usr/bin/bash" | "-bash" => " ", + "zsh" | "/bin/zsh" | "/usr/bin/zsh" | "-zsh" => "󰰶 ", + "fish" => "󰈺 ", + "nushell" => " ", + "ion" => " ", + "oursh" => "󱢇 ", + _ => "󱆃 ", + }; + shell_char.to_string() +} + +pub fn shell(args: Vec) -> String { + if args.len() > 1 { + args[1].clone() // Shell symbol + } else { + "none".to_string() + } +} diff --git a/src/ssh.rs b/src/indicators/ssh.rs similarity index 100% rename from src/ssh.rs rename to src/indicators/ssh.rs diff --git a/src/user.rs b/src/indicators/user.rs similarity index 100% rename from src/user.rs rename to src/indicators/user.rs diff --git a/src/main.rs b/src/main.rs index b1c24fb..4bb9529 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,15 @@ -use colored::{ColoredString, Colorize}; +//use colored::{ColoredString, Colorize}; +use colored::Colorize; use std::env::{args, current_dir, var_os}; -mod git; -mod ssh; -mod user; -use crate::git::*; -use crate::ssh::*; -use crate::user::*; -fn get_shell_char(shell: &str) -> String { - let shell_char = match shell { - "bash" | "/bin/bash" | "/usr/bin/bash" | "-bash" => " ", - "zsh" | "/bin/zsh" | "/usr/bin/zsh" | "-zsh" => "󰰶 ", - "fish" => "󰈺 ", - "nushell" => " ", - "ion" => " ", - "oursh" => "󱢇 ", - _ => "󱆃 ", - }; - shell_char.to_string() +mod indicators { + pub mod error; + pub mod git; + pub mod shell; + pub mod ssh; + pub mod user; } +use crate::indicators::{error::*, git::*, shell::*, ssh::*, user::*}; fn abrev_path(path: &str) -> String { let mut short_dir = path.to_string(); @@ -42,27 +33,15 @@ fn abrev_path(path: &str) -> String { } fn main() -> std::io::Result<()> { - let angle = "❯"; - - let mut err: String = String::new(); + //let angle = "❯"; let args: Vec = args().collect(); - let shell: String; - if args.len() > 1 { - shell = args[1].clone(); // Shell symbol - if args.len() > 2 { - err.clone_from(&args[2]); // Error status - } - } else { - shell = "none".to_string(); - } + let shell: String = shell(args.clone()); let root_indicator = root_indicator(); - let err_indicator = match err.as_str() { - "0" => angle.truecolor(0, 255, 180), - _ => angle.truecolor(255, 53, 94), - }; + let err: String = err(args.clone()); + let err_indicator = err_indicator(err); // SSH status let ssh_char = ssh_char();