From b823586d038b593664c34f9b48e791d423be30be Mon Sep 17 00:00:00 2001 From: candifloss Date: Sat, 23 Nov 2024 16:50:15 +0530 Subject: [PATCH] changed dependancy to ansi_term --- Cargo.lock | 83 ++++++++---------------------------------- Cargo.toml | 2 +- src/indicators/user.rs | 21 +++++++---- src/main.bkp.rs | 55 ++++++++++++++++++++++++++++ src/main.rs | 55 +++++----------------------- 5 files changed, 94 insertions(+), 122 deletions(-) create mode 100644 src/main.bkp.rs diff --git a/Cargo.lock b/Cargo.lock index 932f2f8..5e5dcd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,90 +3,39 @@ version = 3 [[package]] -name = "colored" -version = "2.1.0" +name = "ansi_term" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "lazy_static", - "windows-sys", + "winapi", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "prettyprompt" version = "0.1.0" dependencies = [ - "colored", + "ansi_term", ] [[package]] -name = "windows-sys" -version = "0.48.0" +name = "winapi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "windows-targets", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] -name = "windows-targets" -version = "0.48.5" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 5c2432d..886dff1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] -colored = "2.1.0" +ansi_term = "0.12" diff --git a/src/indicators/user.rs b/src/indicators/user.rs index 00ed681..a1193cb 100644 --- a/src/indicators/user.rs +++ b/src/indicators/user.rs @@ -1,9 +1,14 @@ -use colored::{ColoredString, Colorize}; +use ansi_term::ANSIGenericString; +use ansi_term::Colour::RGB; use std::env::var_os; -//Root user indicator +// User indicator symbol +pub const USER_SYMBOL: &str = "\u{276F}"; // "❯" +pub const ROOT_COL: ansi_term::Colour = RGB(255, 53, 94); // Riot red or something +pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); // A kind of green -pub fn user() -> String { +//Root user indicator +pub fn username() -> String { var_os("USER") .expect("UnknownUser") .to_str() @@ -11,10 +16,10 @@ pub fn user() -> String { .to_string() } -pub fn root_indicator() -> ColoredString { - let angle = "❯"; - match user().as_str() { - "root" => angle.truecolor(255, 53, 94), - _ => angle.truecolor(0, 255, 180), +pub fn indicator() -> ANSIGenericString<'static, str> { + if username() == "root" { + ROOT_COL.paint(USER_SYMBOL) + } else { + NORMIE_COL.paint(USER_SYMBOL) } } diff --git a/src/main.bkp.rs b/src/main.bkp.rs new file mode 100644 index 0000000..df3d877 --- /dev/null +++ b/src/main.bkp.rs @@ -0,0 +1,55 @@ +//use colored::{ColoredString, Colorize}; +use colored::Colorize; +use std::env::{args, current_dir, var_os}; + +mod indicators { + pub mod error; + pub mod git; + pub mod path; + pub mod shell; + pub mod ssh; + pub mod user; +} +use crate::indicators::{error::*, git::*, path::*, shell::*, ssh::*, user::*}; + +fn main() -> std::io::Result<()> { + //let angle = "❯"; + + let args: Vec = args().collect(); + let shell: String = shell(args.clone()); + + let root_indicator = root_indicator(); + + let err: String = err(args.clone()); + let err_indicator = err_indicator(err); + + // SSH status + let ssh_char = ssh_char(); + + //Git status + let git_branch = get_git_branch(); + let git_repo_root = get_git_root(); + let git_repo_name = get_git_repo_name(&git_repo_root.clone()).truecolor(122, 68, 24); + let git_char = get_git_char(&git_branch); + + //pwd + let homedir = homedir(); + let pwd = current_dir()?; + let mut cur_dir = pwd.display().to_string(); + cur_dir = cur_dir.replace(&git_repo_root, ""); // Remove git repo root + cur_dir = cur_dir.replace(&homedir, "~"); // Abreviate homedir with "~" + cur_dir = abrev_path(&cur_dir); + + print!( + "{}{}{}{}{}{}{} ", + ssh_char, + get_shell_char(&shell).truecolor(75, 75, 75), + git_repo_name, + git_char, + cur_dir.italic().truecolor(82, 82, 82), + root_indicator, + err_indicator, + ); + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index df3d877..c425200 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,55 +1,18 @@ -//use colored::{ColoredString, Colorize}; -use colored::Colorize; -use std::env::{args, current_dir, var_os}; - mod indicators { - pub mod error; - pub mod git; - pub mod path; - pub mod shell; - pub mod ssh; pub mod user; } -use crate::indicators::{error::*, git::*, path::*, shell::*, ssh::*, user::*}; +use crate::indicators::user; fn main() -> std::io::Result<()> { - //let angle = "❯"; + //let mut prompt: ANSIGenericString<'static, str> = "".into(); + let mut prompt: String = String::new(); + + let indicate_user:bool = true; - let args: Vec = args().collect(); - let shell: String = shell(args.clone()); - - let root_indicator = root_indicator(); - - let err: String = err(args.clone()); - let err_indicator = err_indicator(err); - - // SSH status - let ssh_char = ssh_char(); - - //Git status - let git_branch = get_git_branch(); - let git_repo_root = get_git_root(); - let git_repo_name = get_git_repo_name(&git_repo_root.clone()).truecolor(122, 68, 24); - let git_char = get_git_char(&git_branch); - - //pwd - let homedir = homedir(); - let pwd = current_dir()?; - let mut cur_dir = pwd.display().to_string(); - cur_dir = cur_dir.replace(&git_repo_root, ""); // Remove git repo root - cur_dir = cur_dir.replace(&homedir, "~"); // Abreviate homedir with "~" - cur_dir = abrev_path(&cur_dir); - - print!( - "{}{}{}{}{}{}{} ", - ssh_char, - get_shell_char(&shell).truecolor(75, 75, 75), - git_repo_name, - git_char, - cur_dir.italic().truecolor(82, 82, 82), - root_indicator, - err_indicator, - ); + if indicate_user { + prompt += &user::indicator().to_string(); + } + print!("{}", prompt); Ok(()) }