From fb80e9c1cd4c2dcbb2d2ba1e2be8c7e19b9f0ce1 Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Thu, 5 Mar 2026 23:54:56 +0100 Subject: very buggy beginning of tab completion --- src/main.rs | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5b195e4..a5820e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,14 +5,14 @@ use std::os::unix::io::AsRawFd; use std::path::Path; use std::process::{Command, Stdio}; +pub mod completion; pub mod cursor; pub mod linebuf; pub mod panic; pub mod parse; pub mod raw; -pub mod run; pub mod reload; -pub mod completion; +pub mod run; use linebuf::LineBuf; use raw::*; @@ -181,7 +181,40 @@ fn event_loop() { } b'\t' => { - todo!() + let cmd = se.line.into_bytes(); + let comp = parse::completion_context(&cmd); + match comp.kind { + parse::CompletionKind::Command => todo!(), + parse::CompletionKind::Argument => { + let suggestions = completion::path_completion(comp.partial); + if suggestions.len() == 0 { + continue; + } + + if suggestions.len() == 1 { + // apply suggestion + todo!("apply suggestion"); + } + + cursor::save(); + + // one line below + print!("\r\n"); + for s in suggestions { + io::stdout().lock().write_all(&s.display).unwrap(); + println!(); + } + + cursor::restore(); + stdout.lock().flush().unwrap(); + } + parse::CompletionKind::None => { + for _ in 0..4 { + se.line.add(b' '); + print!(" ") + } + } + } } // Escape sequence @@ -265,8 +298,10 @@ fn main() { Ok(_) => break, Err(_) => { #[cfg(debug_assertions)] - unsafe { reload::continue_reload() } - }, + unsafe { + reload::continue_reload() + } + } } } -- cgit v1.2.3