Skip to content

Commit

Permalink
Enable to use compopt -o nospace
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Feb 28, 2025
1 parent e3d967d commit e9a9987
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/feeder/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,13 @@ impl Terminal {
self.rewrite(true);
}

pub fn set_double_tab_completion(&mut self) {
let s = self.completion_candidate.clone() + " ";
pub fn set_double_tab_completion(&mut self, core: &ShellCore) {
let tail = match core.current_completion_info.o_options.contains(&"nospace".to_string()) {
true => "",
false => " ",
};

let s = self.completion_candidate.clone() + tail;
self.replace_input(&s);
}

Expand Down
6 changes: 2 additions & 4 deletions src/feeder/terminal/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,15 @@ impl Terminal {
self.tab_row = i%row_num;
}

fn show_list(&mut self, list: &Vec<String>/*, tab_num: usize*/) {
fn show_list(&mut self, list: &Vec<String>) {
if list.is_empty() {
return;
}

let widths: Vec<usize> = list.iter().map(|s| str_width(s)).collect();
let max_entry_width = widths.iter().max().unwrap_or(&1000) + 1;
//let terminal_row_num = Terminal::size().1;
let terminal_row_num = self.size.1;
let col_num = std::cmp::min(
//std::cmp::max(Terminal::size().0 / max_entry_width, 1),
std::cmp::max(self.size.0 / max_entry_width, 1),
list.len()
);
Expand All @@ -231,7 +230,6 @@ impl Terminal {
print!("\r\n");
}

//let (cur_col, cur_row) = self.stdout.cursor_pos().unwrap();
let (cur_col, cur_row) = self.head_to_cursor_pos(self.head, self.prompt_row);

self.check_scroll();
Expand Down
2 changes: 1 addition & 1 deletion src/feeder/terminal/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn char_key(term: &mut Terminal, core: &mut ShellCore, c: &char)
match c {
'\n' => {
if term.completion_candidate.len() > 0 {
term.set_double_tab_completion();
term.set_double_tab_completion(core);
}else{
term.goto(term.chars.len());
term.write("\r\n");
Expand Down
2 changes: 1 addition & 1 deletion test/ok
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
./test_redirects.bash
./test_brace.bash
./test_case.bash
./test_others.bash
./test_calculation.bash
./test_others.bash
./test_compound.bash
./test_parameters.bash
./test_builtins.bash
Expand Down

0 comments on commit e9a9987

Please sign in to comment.