Browse Source

feat: update default prompt style

main
fdai7381 2 years ago
parent
commit
9f67319678
  1. 4
      src/main.rs
  2. 27
      src/prompt.rs

4
src/main.rs

@ -1,6 +1,6 @@
use crate::builtins::BuiltinConfig; use crate::builtins::BuiltinConfig;
use crate::prompt::Prompt; use crate::prompt::Prompt;
use colored::*;
use colored::Colorize;
use execute::interpret; use execute::interpret;
use rustyline::config::Configurer; use rustyline::config::Configurer;
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
@ -26,7 +26,7 @@ fn main() -> Result<()> {
let mut prompt = Prompt::new(); let mut prompt = Prompt::new();
let mut config = BuiltinConfig::new(); let mut config = BuiltinConfig::new();
println!("Welcome, {}.", username().bright_green().bold());
println!("\nWelcome, {}.", username().bright_green().bold());
loop { loop {
let readline = rl.readline(&prompt.get_prompt()); let readline = rl.readline(&prompt.get_prompt());

27
src/prompt.rs

@ -1,3 +1,4 @@
use colored::Colorize;
use std::env; use std::env;
#[derive(Clone)] #[derive(Clone)]
@ -17,7 +18,31 @@ impl PromptStyle {
} }
fn fmt_default(&self) -> String { fn fmt_default(&self) -> String {
"» ".to_string()
let current = env::current_dir().unwrap_or_default();
let home = dirs::home_dir().unwrap_or_default();
let dir = if current.starts_with(home.clone()) {
let mut path = "~/".to_string();
path.push_str(
current
.as_path()
.strip_prefix(home)
.unwrap()
.to_str()
.unwrap_or_default(),
);
path
} else {
current.into_os_string().into_string().unwrap_or_default()
};
format!(
"\n{}\n{} ",
dir.bright_cyan().bold(),
"»".bright_green().bold()
)
} }
fn fmt_simple_directory(&self) -> String { fn fmt_simple_directory(&self) -> String {

Loading…
Cancel
Save