aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs62
1 files changed, 9 insertions, 53 deletions
diff --git a/src/main.rs b/src/main.rs
index b7c3dc5..a9a0ff0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -34,7 +34,7 @@ pub mod wait;
use linebuf::LineBuf;
use raw::*;
-use crate::completion::PathCache;
+use crate::completion::{PathCache, completion};
use crate::ctrlc::CtrlC;
use crate::cursor::{Direction, move_cursor};
use crate::history::HistoryEntry;
@@ -368,65 +368,21 @@ fn event_loop() {
b'\t' => {
let cmd = se.line.pre().to_vec();
drop(se);
- let comp = parse::completion_context(
- &cmd,
- &mut Executor::new_for_completion(session.clone()),
- );
-
- let mut suggestions = match comp.kind {
- parse::CompletionKind::Command => {
- completion::command_completion(session.clone(), comp.partial)
- }
- parse::CompletionKind::Argument => completion::path_completion(comp.partial),
- parse::CompletionKind::Variable => {
- completion::variable_completion(session.clone(), comp.partial)
- }
- parse::CompletionKind::None => continue,
- };
- suggestions.sort_by(|x, y| x.delta.cmp(&y.delta));
- suggestions.dedup_by(|x, y| x.delta == y.delta);
-
- if suggestions.is_empty() {
- continue;
- }
+ let comp = completion(session.clone(), &cmd);
let mut se = session.lock().unwrap();
- if suggestions.len() == 1 {
- // apply suggestion
- se.type_bytes(&suggestions[0].delta);
- continue;
- }
-
- // find longest shared prefix and type it
- {
- let mut longest = &suggestions[0].delta[..];
- for s in suggestions.iter() {
- let mut new = &longest[..0];
- for i in 0..longest.len().min(s.delta.len()) {
- if longest[i] != s.delta[i] {
- break;
- } else {
- new = &s.delta[..=i];
- }
- }
- longest = new;
- }
+ se.type_bytes(&comp.shared_prefix);
- if !longest.is_empty() {
- se.type_bytes(longest);
+ if comp.suggestions.len() > 1 {
+ print!("\r\n");
+ for s in comp.suggestions {
+ io::stdout().lock().write_all(&s.display).unwrap();
+ println!();
}
+ se.reprint_prompt();
}
-
- // one line below
- print!("\r\n");
- for s in suggestions {
- io::stdout().lock().write_all(&s.display).unwrap();
- println!();
- }
-
- se.reprint_prompt();
}
// Escape sequence