Some more autocomplete improvs

This commit is contained in:
Justine 2023-02-07 02:04:38 +01:00
parent aa9cbb323d
commit e7ecb6a7d0
2 changed files with 18 additions and 10 deletions

View File

@ -239,14 +239,16 @@ pub mod shell {
let mut conf = match SqishConf::from_sqishrc() {
Ok(c) => c,
Err(e) => {
let ret_line = format!("Could not build conf, got {}\r\nUsing default\r\n", e);
write!(stdout, "{}", ret_line);
let conf = SqishConf {
promptline: String::from("$COLORGREEN_ [$USER_@$HOSTNAME_] "),
promptline_base: String::from("$COLORGREEN_ [$USER_@$HOSTNAME_] "),
promptline: String::from("!$HISTNUMBER$COLORGREEN_[$USER_@$HOSTNAME_]$COLORRESET_ "),
promptline_base: String::from("!$HISTNUMBER_$COLORGREEN_[$USER_@$HOSTNAME_]$COLORRESET_ "),
aliases: HashMap::new(),
hotkeys: HashMap::new(),
};
let ret_line = format!("Could not build conf, got {}\
\r\nUsing default promptline:\
\r\n{}\r\n", e, conf.promptline);
write!(stdout, "{}", ret_line);
conf
},
};
@ -268,7 +270,7 @@ pub mod shell {
//Search
*&mut mycommand = replace_signs(&mycommand);
let (res, list) = Search::build(&mycommand).unwrap().autocomplete();
write!(stdout, "\r\n{}\r\n", list);
if list.len() > 0 { write!(stdout, "\r\n{}\r\n", list); }
mycommand.clear();
mycommand.push_str(&res);
max_pos = res.len();
@ -286,7 +288,7 @@ pub mod shell {
let _res = handle_input(&comm);
RawTerminal::activate_raw_mode(&stdout);
mycommand.clear();
//Proper printing
//Proper printing of return code
//for line in res.split('\n') {
// if line != "\r" {
// write!(stdout, "\r\n{}", line);
@ -295,6 +297,7 @@ pub mod shell {
&conf.update_prompt(get_curr_history_number());
write!(stdout, "\r\n{}", conf.promptline).unwrap();
stdout.flush();
current_number += 1;
} else if mycommand == String::from("exit") {
write!(stdout, "\r\n Sayonara \r\n");
break;

View File

@ -94,12 +94,12 @@ impl Search {
SearchType::CmdSearch => autocomplete_cmd(&self.searchee, &self),
SearchType::FileSearch => match autocomplete_file(&self) {
Ok(t) => t,
Err(_) => (String::new(), String::new()),
Err(_) => (format!("{}{}", &self.command, &self.searchee), String::new()),
}
};
if res.len() < 1 {
*&mut res = format!("{} {}", &self.command, &self.searchee);
*&mut res = format!("{}{}", &self.command, &self.searchee);
}
return (res, res_lines);
@ -185,7 +185,12 @@ fn autocomplete_file(search: &Search) -> std::io::Result<(String, String)> {
//Handle returning the longest sequence of characters between two or more matching files
if nbr_found > 1 {
let longest = find_common_chars(results);
*&mut last_found = longest;
*&mut last_found = longest;
}
if nbr_found == 0 {
let ret_val = format!("{}{}", &search.command, &search.searchee);
return Ok((ret_val, String::new()));
}
//Handle the path when tabbing in a long path, zsh-like
@ -214,7 +219,7 @@ fn autocomplete_cmd(input: &String, search: &Search) -> (String, String) {
return (res_string, res_list);
} else if found_bins.len() == 0 {
let list = String::from("Nothing adequate.");
let res = String::new();
let res = String::from("");
return (res, list);
} else {
let mut all_res = String::new();