Browse Source

feat: add filename completion

main
fdai7381 2 years ago
committed by fdai7451
parent
commit
0c54d96ee3
  1. 12
      Cargo.lock
  2. 1
      Cargo.toml
  3. 21
      src/main.rs

12
Cargo.lock

@ -375,6 +375,7 @@ dependencies = [
"once_cell",
"regex",
"rustyline",
"rustyline-derive",
"shlex",
"sysinfo",
"uname",
@ -505,6 +506,17 @@ dependencies = [
"winapi",
]
[[package]]
name = "rustyline-derive"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "107c3d5d7f370ac09efa62a78375f94d94b8a33c61d8c278b96683fb4dbf2d8d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "scopeguard"
version = "1.1.0"

1
Cargo.toml

@ -11,6 +11,7 @@ dirs = "4.0"
once_cell = "1.17"
regex = "1.7"
rustyline = "10.1"
rustyline-derive = "0.7"
shlex = "1.1"
sysinfo = "0.27"
uname = "0.1"

21
src/main.rs

@ -2,9 +2,11 @@ use crate::builtins::BuiltinConfig;
use crate::prompt::Prompt;
use colored::Colorize;
use execute::interpret;
use rustyline::completion::FilenameCompleter;
use rustyline::config::Configurer;
use rustyline::error::ReadlineError;
use rustyline::{Editor, Result};
use rustyline::{CompletionType, Config, Editor, Result};
use rustyline_derive::{Completer, Helper, Highlighter, Hinter, Validator};
use whoami::username;
mod builtins;
@ -14,13 +16,28 @@ mod parse;
mod preprocess;
mod prompt;
#[derive(Completer, Helper, Highlighter, Hinter, Validator)]
struct EditorHelper {
#[rustyline(Completer)]
completer: FilenameCompleter,
}
fn main() -> Result<()> {
let (ctrlc_send, ctrlc_recv) = crossbeam_channel::unbounded::<()>();
let _ = ctrlc::set_handler(move || {
let _ = ctrlc_send.send(());
});
let mut rl = Editor::<()>::new()?;
let config = Config::builder()
.completion_type(CompletionType::List)
.build();
let helper = EditorHelper {
completer: FilenameCompleter::new(),
};
let mut rl = Editor::with_config(config)?;
rl.set_helper(Some(helper));
rl.set_auto_add_history(true);
let mut prompt = Prompt::new();

Loading…
Cancel
Save