changed dependancy to ansi_term

This commit is contained in:
Candifloss 2024-11-23 16:50:15 +05:30
parent 7ed36ce471
commit b823586d03
5 changed files with 94 additions and 122 deletions

83
Cargo.lock generated
View File

@ -3,90 +3,39 @@
version = 3 version = 3
[[package]] [[package]]
name = "colored" name = "ansi_term"
version = "2.1.0" version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [ dependencies = [
"lazy_static", "winapi",
"windows-sys",
] ]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "prettyprompt" name = "prettyprompt"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"colored", "ansi_term",
] ]
[[package]] [[package]]
name = "windows-sys" name = "winapi"
version = "0.48.0" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [ dependencies = [
"windows-targets", "winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
] ]
[[package]] [[package]]
name = "windows-targets" name = "winapi-i686-pc-windows-gnu"
version = "0.48.5" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
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",
]
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "winapi-x86_64-pc-windows-gnu"
version = "0.48.5" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[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"

View File

@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
colored = "2.1.0" ansi_term = "0.12"

View File

@ -1,9 +1,14 @@
use colored::{ColoredString, Colorize}; use ansi_term::ANSIGenericString;
use ansi_term::Colour::RGB;
use std::env::var_os; 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") var_os("USER")
.expect("UnknownUser") .expect("UnknownUser")
.to_str() .to_str()
@ -11,10 +16,10 @@ pub fn user() -> String {
.to_string() .to_string()
} }
pub fn root_indicator() -> ColoredString { pub fn indicator() -> ANSIGenericString<'static, str> {
let angle = ""; if username() == "root" {
match user().as_str() { ROOT_COL.paint(USER_SYMBOL)
"root" => angle.truecolor(255, 53, 94), } else {
_ => angle.truecolor(0, 255, 180), NORMIE_COL.paint(USER_SYMBOL)
} }
} }

55
src/main.bkp.rs Normal file
View File

@ -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<String> = 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(())
}

View File

@ -1,55 +1,18 @@
//use colored::{ColoredString, Colorize};
use colored::Colorize;
use std::env::{args, current_dir, var_os};
mod indicators { mod indicators {
pub mod error;
pub mod git;
pub mod path;
pub mod shell;
pub mod ssh;
pub mod user; pub mod user;
} }
use crate::indicators::{error::*, git::*, path::*, shell::*, ssh::*, user::*}; use crate::indicators::user;
fn main() -> std::io::Result<()> { 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<String> = args().collect(); if indicate_user {
let shell: String = shell(args.clone()); prompt += &user::indicator().to_string();
}
let root_indicator = root_indicator(); print!("{}", prompt);
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(()) Ok(())
} }