changed type of strings

This commit is contained in:
Candifloss 2024-11-28 16:21:38 +05:30
parent a0c6f3a71e
commit e836ad40ac

View File

@ -11,11 +11,12 @@ use crate::indicators::git;
use crate::indicators::pwd;
use crate::indicators::ssh;
use crate::indicators::user;
use ansi_term::{ANSIGenericString, ANSIGenericStrings};
fn main() {
let cmd_args: Vec<String> = std::env::args().collect();
let cmd_args: Vec<String> = std::env::args().collect(); // Cmd-line args
let mut components: Vec<String> = Vec::new();
let mut components: Vec<ANSIGenericString<'static, str>> = Vec::new(); // The components will be concated into one string
let indicate_user: bool = true;
let indicate_ssh: bool = true;
@ -25,23 +26,27 @@ fn main() {
let abbrev_home: bool = true;
let shorten_path: bool = true;
let replace_repo: bool = true;
let mut git_info = None;
let git_info: Option<(String, String)> = if indicate_git_branch || replace_repo {
git::info()
} else {
None
};
if indicate_ssh {
components.push(ssh::indicator().to_string());
components.push(ssh::indicator());
}
if indicate_git_branch {
git_info = git::info();
match git_info {
Some(ref info) => components.push(git::indicator(Some(info.1.clone())).to_string()),
None => components.push(git::indicator(None).to_string()),
Some(ref info) => components.push(git::indicator(Some(info.1.clone()))),
None => components.push(git::indicator(None)),
}
}
if indicate_user {
components.push(user::indicator().to_string());
components.push(user::indicator());
}
if indicate_err {
components.push(error::indicator(cmd_args).to_string());
components.push(error::indicator(cmd_args));
}
if show_pwd {
let repo_path = match git_info {
@ -50,9 +55,9 @@ fn main() {
};
components.insert(
0,
pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path).to_string(),
pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path),
);
}
let prompt = components.join("");
let prompt: ANSIGenericStrings<'_, str> = ANSIGenericStrings(&components[..]);
print!("{prompt} ");
}