Use Updated Library

This commit is contained in:
Candifloss 2026-07-16 13:07:27 +05:30
parent 905d3489f7
commit 7297a78fba
8 changed files with 54 additions and 60 deletions

47
Cargo.lock generated
View File

@ -2,47 +2,40 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.180" version = "0.2.180"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]]
name = "nu-ansi-term"
version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys",
]
[[package]] [[package]]
name = "prettyprompt" name = "prettyprompt"
version = "0.3.0" version = "0.3.0"
dependencies = [ dependencies = [
"ansi_term",
"libc", "libc",
"nu-ansi-term",
] ]
[[package]] [[package]]
name = "winapi" name = "windows-link"
version = "0.3.9" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [ dependencies = [
"winapi-i686-pc-windows-gnu", "windows-link",
"winapi-x86_64-pc-windows-gnu",
] ]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -4,8 +4,9 @@ version = "0.3.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
ansi_term = "0.12" #ansi_term = "0.12"
libc = "0.2.180" libc = "0.2.180"
nu-ansi-term = "0.50.3"
[[bin]] [[bin]]
name = "prettyprompt" name = "prettyprompt"

View File

@ -1,12 +1,12 @@
use ansi_term::ANSIGenericString; use nu_ansi_term::AnsiGenericString;
use ansi_term::Colour::RGB; use nu_ansi_term::Color::Rgb;
pub const ERR_SYMBOL: &str = "\u{276F}"; // Error indicator symbol: "" pub const ERR_SYMBOL: &str = "\u{276F}"; // Error indicator symbol: ""
pub const ERR_COL: ansi_term::Colour = RGB(255, 53, 94); // Error pub const ERR_COL: nu_ansi_term::Color = Rgb(255, 53, 94); // Error
pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); // Success pub const NORMIE_COL: nu_ansi_term::Color = Rgb(0, 255, 180); // Success
// Error indicator // Error indicator
pub fn indicator(args: &[String]) -> ANSIGenericString<'static, str> { pub fn indicator(args: &[String]) -> AnsiGenericString<'static, str> {
let exit_code = args.get(1).map_or("0", String::as_str); // Default to "0" (success, no error) if arg missing let exit_code = args.get(1).map_or("0", String::as_str); // Default to "0" (success, no error) if arg missing
if exit_code == "0" { if exit_code == "0" {
NORMIE_COL.paint(ERR_SYMBOL) // Success NORMIE_COL.paint(ERR_SYMBOL) // Success

View File

@ -1,13 +1,13 @@
use ansi_term::ANSIGenericString; use nu_ansi_term::AnsiGenericString;
use ansi_term::Colour::RGB; use nu_ansi_term::Color::Rgb;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
pub const GIT_SYMBOL: &str = "\u{276F}"; // Git indicator symbol: "" pub const GIT_SYMBOL: &str = "\u{276F}"; // Git indicator symbol: ""
pub const MAIN_COL: ansi_term::Colour = RGB(178, 98, 44); pub const MAIN_COL: nu_ansi_term::Color = Rgb(178, 98, 44);
pub const DEV_COL: ansi_term::Colour = RGB(54, 159, 150); pub const DEV_COL: nu_ansi_term::Color = Rgb(54, 159, 150);
pub const DEFAULT_BRANCH_COL: ansi_term::Colour = RGB(255, 255, 255); pub const DEFAULT_BRANCH_COL: nu_ansi_term::Color = Rgb(255, 255, 255);
pub const NORMIE_COL: ansi_term::Colour = RGB(82, 82, 82); pub const NORMIE_COL: nu_ansi_term::Color = Rgb(82, 82, 82);
/// Returns the repo's root and branch, if present /// Returns the repo's root and branch, if present
pub fn info() -> Option<(String, String)> { pub fn info() -> Option<(String, String)> {
@ -36,7 +36,7 @@ pub fn repo_name(path: &str) -> String {
} }
/// Git branch indicator /// Git branch indicator
pub fn indicator(branch: Option<String>) -> ANSIGenericString<'static, str> { pub fn indicator(branch: Option<String>) -> AnsiGenericString<'static, str> {
match branch { match branch {
Some(b) => match b.as_str() { Some(b) => match b.as_str() {
"main" => MAIN_COL.paint(GIT_SYMBOL), "main" => MAIN_COL.paint(GIT_SYMBOL),

View File

@ -1,11 +1,11 @@
use crate::indicators::git::{MAIN_COL, repo_name}; use crate::indicators::git::{MAIN_COL, repo_name};
use ansi_term::ANSIGenericString; use nu_ansi_term::AnsiGenericString;
use ansi_term::Colour::RGB; use nu_ansi_term::Color::Rgb;
use std::env::current_dir; use std::env::current_dir;
pub const UNKNOWN_PATH: &str = "\u{2248}"; // "≈" pub const UNKNOWN_PATH: &str = "\u{2248}"; // "≈"
pub const PATH_COL: ansi_term::Colour = RGB(82, 82, 82); pub const PATH_COL: nu_ansi_term::Color = Rgb(82, 82, 82);
pub const REPO_COL: ansi_term::Colour = RGB(55, 120, 130); pub const REPO_COL: nu_ansi_term::Color = Rgb(55, 120, 130);
/// Find the current user's home directory. /// Find the current user's home directory.
fn home_dir() -> Option<String> { fn home_dir() -> Option<String> {
@ -73,7 +73,7 @@ pub fn pwd(
shorten_path: bool, shorten_path: bool,
replace_repo: bool, replace_repo: bool,
git_repo: Option<String>, git_repo: Option<String>,
) -> ANSIGenericString<'static, str> { ) -> AnsiGenericString<'static, str> {
let mut slash_limit: u8 = 3; // Max number of slashes let mut slash_limit: u8 = 3; // Max number of slashes
let mut path = full_path(); // Get the full path of he current directory let mut path = full_path(); // Get the full path of he current directory

View File

@ -1,10 +1,10 @@
use ansi_term::ANSIGenericString; use nu_ansi_term::AnsiGenericString;
use ansi_term::Colour::RGB; use nu_ansi_term::Color::Rgb;
use std::env::var_os; // For environment variables use std::env::var_os; // For environment variables
pub const SSH_SYMBOL: &str = "\u{276F}"; // SSH indicator symbol: "" pub const SSH_SYMBOL: &str = "\u{276F}"; // SSH indicator symbol: ""
pub const SSH_COL: ansi_term::Colour = RGB(255, 149, 0); // In SSH session pub const SSH_COL: nu_ansi_term::Color = Rgb(255, 149, 0); // In SSH session
pub const NORMIE_COL: ansi_term::Colour = RGB(82, 82, 82); // Non-SSH session pub const NORMIE_COL: nu_ansi_term::Color = Rgb(82, 82, 82); // Non-SSH session
const SSH_ENV_VARS: [&str; 3] = ["SSH_TTY", "SSH_CONNECTION", "SSH_CLIENT"]; // Environment variables normally present in SSH sessions const SSH_ENV_VARS: [&str; 3] = ["SSH_TTY", "SSH_CONNECTION", "SSH_CLIENT"]; // Environment variables normally present in SSH sessions
/// Checks if current session is an SSH session /// Checks if current session is an SSH session
@ -15,7 +15,7 @@ fn is_ssh_session() -> bool {
} }
/// SSH shell indicator /// SSH shell indicator
pub fn indicator() -> ANSIGenericString<'static, str> { pub fn indicator() -> AnsiGenericString<'static, str> {
let is_ssh: bool = is_ssh_session(); let is_ssh: bool = is_ssh_session();
if is_ssh { if is_ssh {
SSH_COL.paint(SSH_SYMBOL) SSH_COL.paint(SSH_SYMBOL)

View File

@ -1,11 +1,11 @@
use ansi_term::ANSIGenericString; use nu_ansi_term::AnsiGenericString;
use ansi_term::Colour::RGB; use nu_ansi_term::Color::Rgb;
use libc::geteuid; use libc::geteuid;
pub const USER_SYMBOL: &str = "\u{276F}"; // User indicator symbol: "" pub const USER_SYMBOL: &str = "\u{276F}"; // User indicator symbol: ""
pub const ROOT_COL: ansi_term::Colour = RGB(255, 53, 94); // If the user is root pub const ROOT_COL: nu_ansi_term::Color = Rgb(255, 53, 94); // If the user is root
pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); // Regular user pub const NORMIE_COL: nu_ansi_term::Color = Rgb(0, 255, 180); // Regular user
// Check if the current user is root // Check if the current user is root
pub fn is_root() -> bool { pub fn is_root() -> bool {
@ -13,7 +13,7 @@ pub fn is_root() -> bool {
} }
/// Root user indicator /// Root user indicator
pub fn indicator() -> ANSIGenericString<'static, str> { pub fn indicator() -> AnsiGenericString<'static, str> {
if is_root() { if is_root() {
ROOT_COL.paint(USER_SYMBOL) ROOT_COL.paint(USER_SYMBOL)
} else { } else {

View File

@ -6,13 +6,13 @@ mod indicators {
} }
use crate::indicators::{error, git, ssh, user}; use crate::indicators::{error, git, ssh, user};
use ansi_term::{ANSIGenericString, ANSIGenericStrings}; use nu_ansi_term::{AnsiGenericString, AnsiGenericStrings};
// Add a component to the prompt if the condition is true. // Add a component to the prompt if the condition is true.
fn add_component( fn add_component(
components: &mut Vec<ANSIGenericString<'static, str>>, // Vector to hold components of the prompt. components: &mut Vec<AnsiGenericString<'static, str>>, // Vector to hold components of the prompt.
condition: bool, // Condition to add the component condition: bool, // Condition to add the component
component_fn: impl FnOnce() -> ANSIGenericString<'static, str>, // Function to create the component(takes no arguments, returns `ANSIGenericString`) is passed here. component_fn: impl FnOnce() -> AnsiGenericString<'static, str>, // Function to create the component(takes no arguments, returns `AnsiGenericString`) is passed here.
) { ) {
if condition { if condition {
components.push(component_fn()); // Push the generated component to the vector. components.push(component_fn()); // Push the generated component to the vector.
@ -23,7 +23,7 @@ fn main() {
let cmd_args: Vec<String> = std::env::args().collect(); // Command-line args let cmd_args: Vec<String> = std::env::args().collect(); // Command-line args
// Vector to hold the different parts of the prompt. // Vector to hold the different parts of the prompt.
let mut components: Vec<ANSIGenericString<'static, str>> = Vec::new(); // The components will be concatenated into a single string in the end. let mut components: Vec<AnsiGenericString<'static, str>> = Vec::new(); // The components will be concatenated into a single string in the end.
// Hard-coded configuration. This will be replaced by a configuration file in a future version // Hard-coded configuration. This will be replaced by a configuration file in a future version
let indicate_user: bool = true; let indicate_user: bool = true;
@ -49,7 +49,7 @@ fn main() {
}); });
// Finally, combine the parts into a single prompts string // Finally, combine the parts into a single prompts string
let prompt: ANSIGenericStrings<'_, str> = ANSIGenericStrings(&components[..]); let prompt: AnsiGenericStrings<'_, str> = AnsiGenericStrings(&components[..]);
// `print!()` prevents an extra newline, unlike `println!()` // `print!()` prevents an extra newline, unlike `println!()`
print!("{prompt} "); // A trailing space for aesthetic formatting. print!("{prompt} "); // A trailing space for aesthetic formatting.
} }