From 28783a5d1b47ad83bb8f510a7ebfae8ead3d31f8 Mon Sep 17 00:00:00 2001 From: Justine Pelletreau Date: Fri, 3 Feb 2023 13:37:45 +0100 Subject: [PATCH] Removed warnings --- README.md | 4 ++++ src/lib.rs | 10 +--------- src/shell/autocomplete.rs | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f0cfc27..bb17bf9 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,7 @@ Rust Shell. This is an attempt to create a simple shell in Rust, because why not !!! LOOK into the pty crate to handle pseudoterminals such as in top or ssh My starting point is [this article](https://www.joshmcguigan.com/blog/build-your-own-shell-rust/) which is excellent. I will start with the final form of a shell given in the article and try to reformat it: + +## To fix +* Autocomplete : when nothing found, return input +* Autocomplete : Weird permission issues sometimes (ignore unallowed files and folders) diff --git a/src/lib.rs b/src/lib.rs index c69bfb0..c1ac871 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,12 +236,6 @@ pub mod shell { let mut current_pos: usize = 0; let mut max_pos: usize = 0; - //Used to keep the result of the last autocomplete - //Next time we press tab we get a different result so that we can - //rotate between files in the dir for example - //Resetted by pressing enter - let mut prev_autocomplete = String::new(); - //Initialize write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", prompt); stdout.flush(); @@ -255,8 +249,7 @@ pub mod shell { continue; } //Search - let (res, list) = autocomplete(&mycommand, &prev_autocomplete); - *&mut prev_autocomplete = String::from(res.as_str()); + let (res, list) = autocomplete(&mycommand); write!(stdout, "\r\n{}\r\n", list); mycommand.clear(); mycommand.push_str(&res); @@ -267,7 +260,6 @@ pub mod shell { } Key::Char('\n') => { - *&mut prev_autocomplete = String::new(); current_number = get_curr_history_number(); prompt = build_prompt(¤t_number); current_pos = 0; diff --git a/src/shell/autocomplete.rs b/src/shell/autocomplete.rs index d5cc428..b1da450 100644 --- a/src/shell/autocomplete.rs +++ b/src/shell/autocomplete.rs @@ -55,7 +55,7 @@ fn autocomplete_file(input: &String) -> std::io::Result<(String, String)> { if input_searchee.contains('/') { //Correctly taking first and last part... let splitted_searchstring = &input_searchee.split('/'); - let mut trimmed_searchee = &splitted_searchstring.clone().last().unwrap(); + let trimmed_searchee = &splitted_searchstring.clone().last().unwrap(); let splitted_searchstring = &mut input_searchee.clone().split('/').collect::>(); splitted_searchstring.pop(); let mut tosearch = splitted_searchstring.join("/");