src/cli/readline.rs: moved readline related code here
This commit is contained in:
		| @ -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 { | ||||
|  | ||||
| } | ||||
|  | ||||
							
								
								
									
										40
									
								
								src/cli/readline.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								src/cli/readline.rs
									
									
									
									
									
										Normal file
									
								
							| @ -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 {} | ||||
		Reference in New Issue
	
	Block a user