use rustyline::{completion::*, highlight::*, hint::*, validate::*, Context, Helper, Result}; use queryscript::{ compile, compile::{autocomplete::AutoCompleter, schema}, }; use std::cell::RefCell; use std::rc::Rc; pub struct RustylineHelper(AutoCompleter); impl RustylineHelper { pub fn new( compiler: compile::Compiler, schema: schema::Ref, curr_buffer: Rc>, ) -> RustylineHelper { RustylineHelper(AutoCompleter::new(compiler, schema, curr_buffer)) } } impl Completer for RustylineHelper { type Candidate = Pair; fn complete( &self, line: &str, pos: usize, _ctx: &Context<'_>, ) -> Result<(usize, Vec)> { let (pos, suggestions) = self.0.auto_complete(line, pos); Ok(( pos, suggestions .into_iter() .map(|s| Pair { display: s.to_string(), replacement: s.to_string(), }) .collect(), )) } } impl Hinter for RustylineHelper { type Hint = String; fn hint(&self, _line: &str, _pos: usize, _ctx: &Context<'_>) -> Option { if self.0.debug { Some(format!(" {}", self.0.stats.borrow())) } else { None } } } impl Highlighter for RustylineHelper {} impl Validator for RustylineHelper {} impl Helper for RustylineHelper {}