Some more tab completion work
This commit is contained in:
parent
fe1a508e25
commit
41c9dfae06
@ -130,43 +130,78 @@ fn run_noninteractive(filename: &str, languages: Vec<Box<ProgrammingLanguageInte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum CommandTree {
|
||||||
|
Terminal(String),
|
||||||
|
NonTerminal(String, Vec<CommandTree>)
|
||||||
|
}
|
||||||
|
|
||||||
struct TabCompleteHandler {
|
struct TabCompleteHandler {
|
||||||
passes: Vec<String>,
|
passes: Vec<String>,
|
||||||
sigil: char,
|
sigil: char,
|
||||||
|
top_level_commands: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
use linefeed::complete::{Completion, Completer};
|
||||||
|
use linefeed::terminal::Terminal;
|
||||||
|
|
||||||
impl TabCompleteHandler {
|
impl TabCompleteHandler {
|
||||||
fn complete_interpreter_directive(&self, line: &str, pos: usize) -> rustyline::Result<(usize, Vec<String>)> {
|
fn new(sigil: char, passes: Vec<String>) -> TabCompleteHandler {
|
||||||
let mut iter = line.chars();
|
TabCompleteHandler {
|
||||||
iter.next();
|
passes,
|
||||||
let commands: Vec<&str> = iter
|
sigil,
|
||||||
.as_str()
|
top_level_commands: vec![
|
||||||
.split_whitespace()
|
"exit".to_string(),
|
||||||
.collect();
|
"quit".to_string(),
|
||||||
println!("POS {}---", pos);
|
"lang".to_string(),
|
||||||
let completes = match &commands[..] {
|
"debug".to_string(),
|
||||||
&["debug", "show"] | &["debug", "hide"] => self.passes.clone(),
|
]
|
||||||
&["debug"] | &["debug", _] => vec!["passes".to_string(), "show".to_string(), "hide".to_string()],
|
}
|
||||||
&[_cmd] => vec!["debug".to_string()],
|
}
|
||||||
_ => vec![],
|
}
|
||||||
};
|
|
||||||
Ok((pos, completes))
|
impl<T: Terminal> Completer<T> for TabCompleteHandler {
|
||||||
}
|
fn complete(&self, word: &str, prompter: &linefeed::prompter::Prompter<T>, start: usize, end: usize) -> Option<Vec<Completion>> {
|
||||||
}
|
let line = prompter.buffer();
|
||||||
*/
|
|
||||||
|
if line.starts_with(&format!("{}", self.sigil)) {
|
||||||
/*
|
let mut words = line[1..(if start == 0 { 1 } else { start })].split_whitespace();
|
||||||
impl rustyline::completion::Completer for TabCompleteHandler {
|
let mut completions = Vec::new();
|
||||||
fn complete(&self, line: &str, pos: usize) -> rustyline::Result<(usize, Vec<String>)> {
|
match words.next() {
|
||||||
if line.starts_with(&format!("{}", self.sigil)) {
|
None => {
|
||||||
self.complete_interpreter_directive(line, pos)
|
let word = word.get(1..).unwrap();
|
||||||
} else {
|
for cmd in self.top_level_commands.iter() {
|
||||||
Ok((pos, vec!(format!("tab-completion-no-done"), format!("tab-completion-still-not-done"))))
|
if cmd.starts_with(word) {
|
||||||
|
completions.push(
|
||||||
|
Completion {
|
||||||
|
completion: format!(":{}", cmd),
|
||||||
|
display: Some(cmd.clone()),
|
||||||
|
suffix: linefeed::complete::Suffix::Some(' ')
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some("debug") => match words.next() {
|
||||||
|
None => for cmd in ["show", "hide", "passes"].iter() {
|
||||||
|
if cmd.starts_with(word) {
|
||||||
|
completions.push(Completion::simple(cmd.to_string()));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some("show") | Some("hide") => for pass in self.passes.iter() {
|
||||||
|
if pass.starts_with(word) {
|
||||||
|
completions.push(Completion::simple(pass.to_string()));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => return None,
|
||||||
|
},
|
||||||
|
_ => return None
|
||||||
|
}
|
||||||
|
Some(completions)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
struct Repl {
|
struct Repl {
|
||||||
options: EvalOptions,
|
options: EvalOptions,
|
||||||
@ -232,10 +267,10 @@ impl Repl {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let language_name = self.languages[self.current_language_index].get_language_name();
|
let language_name = self.languages[self.current_language_index].get_language_name();
|
||||||
/*
|
|
||||||
let tab_complete_handler = TabCompleteHandler { sigil: self.interpreter_directive_sigil, passes: self.get_cur_language().get_passes() };
|
let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, self.get_cur_language().get_passes());
|
||||||
self.line_reader.set_completer(Some(tab_complete_handler));
|
self.line_reader.set_completer(std::sync::Arc::new(tab_complete_handler));
|
||||||
*/
|
|
||||||
let prompt_str = format!("{} >> ", language_name);
|
let prompt_str = format!("{} >> ", language_name);
|
||||||
self.line_reader.set_prompt(&prompt_str);
|
self.line_reader.set_prompt(&prompt_str);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user