src/cli/readline.rs: moved readline related code here
This commit is contained in:
parent
5d64a0d083
commit
a810e05288
|
@ -22,6 +22,9 @@ pub use getopts::*;
|
|||
mod command;
|
||||
pub use command::*;
|
||||
|
||||
mod readline;
|
||||
pub use readline::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use proxmox::api::ApiMethod;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn get_completions(
|
||||
|
@ -34,43 +32,3 @@ pub fn get_completions(
|
|||
|
||||
(start, completions)
|
||||
}
|
||||
|
||||
pub struct CliHelper {
|
||||
cmd_def: Arc<CommandLineInterface>,
|
||||
}
|
||||
|
||||
impl CliHelper {
|
||||
|
||||
pub fn new(cmd_def: CommandLineInterface) -> Self {
|
||||
Self { cmd_def: Arc::new(cmd_def) }
|
||||
}
|
||||
|
||||
pub fn cmd_def(&self) -> Arc<CommandLineInterface> {
|
||||
self.cmd_def.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl rustyline::completion::Completer for CliHelper {
|
||||
type Candidate = String;
|
||||
|
||||
fn complete(
|
||||
&self,
|
||||
line: &str,
|
||||
pos: usize,
|
||||
_ctx: &rustyline::Context<'_>,
|
||||
) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
|
||||
|
||||
let line = &line[..pos];
|
||||
|
||||
let (start, completions) = super::get_completions(&*self.cmd_def, line, false);
|
||||
|
||||
return Ok((start, completions));
|
||||
}
|
||||
}
|
||||
|
||||
impl rustyline::hint::Hinter for CliHelper {}
|
||||
impl rustyline::highlight::Highlighter for CliHelper {}
|
||||
|
||||
impl rustyline::Helper for CliHelper {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub struct CliHelper {
|
||||
cmd_def: Arc<CommandLineInterface>,
|
||||
}
|
||||
|
||||
impl CliHelper {
|
||||
|
||||
pub fn new(cmd_def: CommandLineInterface) -> Self {
|
||||
Self { cmd_def: Arc::new(cmd_def) }
|
||||
}
|
||||
|
||||
pub fn cmd_def(&self) -> Arc<CommandLineInterface> {
|
||||
self.cmd_def.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl rustyline::completion::Completer for CliHelper {
|
||||
type Candidate = String;
|
||||
|
||||
fn complete(
|
||||
&self,
|
||||
line: &str,
|
||||
pos: usize,
|
||||
_ctx: &rustyline::Context<'_>,
|
||||
) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
|
||||
|
||||
let line = &line[..pos];
|
||||
|
||||
let (start, completions) = super::get_completions(&*self.cmd_def, line, false);
|
||||
|
||||
return Ok((start, completions));
|
||||
}
|
||||
}
|
||||
|
||||
impl rustyline::hint::Hinter for CliHelper {}
|
||||
impl rustyline::highlight::Highlighter for CliHelper {}
|
||||
impl rustyline::Helper for CliHelper {}
|
Loading…
Reference in New Issue