Fixed history and cd without args

This commit is contained in:
Justine
2023-02-19 20:32:17 +01:00
parent 2a0866ab64
commit 0f6bd3337a
4 changed files with 15 additions and 15 deletions

View File

@ -45,7 +45,8 @@ pub mod shell {
match command {
"cd" => {
let new_dir = args.peekable().peek().map_or("/", |x| *x);
let homedir = dirs::home_dir().unwrap().into_os_string().into_string().unwrap();
let new_dir = args.peekable().peek().map_or(homedir.as_str(), |x| *x);
let root = Path::new(new_dir);
if let Err(e) = env::set_current_dir(&root) {
eprintln!(" Err: {}", e);
@ -113,8 +114,7 @@ pub mod shell {
.expect("Could not get retcode")
.to_string();
previous_command = None;
let format_res = format!("{}...Exit: {}\r\n",
color::Fg(color::Cyan),
let format_res = format!("{}",
status);
let _ = &mut resultat.push_str(&format_res);
}
@ -218,14 +218,14 @@ pub mod shell {
if (mycommand != &String::from("\n")) && (mycommand != &String::from("exit")) {
let comm = replace_signs(&mycommand);
RawTerminal::suspend_raw_mode(&stdout);
let _res = handle_input(&comm);
let res = handle_input(&comm);
RawTerminal::activate_raw_mode(&stdout);
mycommand.clear();
//for line in res.split('\n') {
// if line != "\r" {
// write!(stdout, "\r\n{}", line);
// }
//}
for line in res.split('\n') {
if line != "\r" {
write!(stdout, "\r\n{}", line);
}
}
conf.update_prompt(get_curr_history_number());
write!(stdout, "\r\n{}", conf.promptline).unwrap();
stdout.flush();
@ -314,7 +314,7 @@ pub mod shell {
for c in stdin.keys() {
let k = c.unwrap();
match k {
Key::Char('\t') => {
Key::Char('\t') => {
//Do NOT search on an empty command
if *&mycommand.len() == 0 {
continue;
@ -330,7 +330,6 @@ pub mod shell {
write!(stdout, "\r\n{}{}", conf.promptline, res);
stdout.flush();
}
Key::Char('\n') => {
current_pos = 0;
max_pos = 0;