[−][src]Struct shli::prompt::Prompt
Config struct for building command line interfaces. An example:
use shli::{Prompt,Command}; let mut p = Prompt::new("> ".to_string(), vec!( Command::new("print"), Command::new("echo"), Command::new("cat").arg("--help"), Command::new("exit") ));
Now, use the read_commandline
method to let the user type a command.
It will tab complete print
, echo
, cat
, cat --help
and exit
.
Fields
prompt_text: String
history: Vec<String>
commands: Vec<Command>
Methods
impl Prompt
[src]
pub fn new(prompt_text: String, commands: Vec<Command>) -> Prompt
[src]
Creates a new Prompt instance.
prompt_text
is the text written before the user input.
commands
is the list of available commands used by tab completion.
pub fn read_commandline(&mut self) -> Result<Vec<String>>
[src]
Prompt for a single command line.
This function reads and returns a command line. Line editing with backspace and ALT+backspace is supported.
If TAB is pressed by the user, the callback function completion
is asked
for possible argument completion. If it returns exactly 1 completion, it
is used, if it returns more, they are displayed.
If Ctrl+C is pressed, this function returns Err(Error::new(ErrorKind::Other, "Ctrl-C pressed.")
,
while an EOF of stdin
or Ctrl+D will return the error type ErrorKind::UnexpectedEof
.
On success, read_commandline
returns a Vector of command line components (command + arguments).
For example, the following input:
> print out "example command"
will return vec!["print", "out", "example command"]
.
Auto Trait Implementations
impl RefUnwindSafe for Prompt
impl Send for Prompt
impl Sync for Prompt
impl Unpin for Prompt
impl UnwindSafe for Prompt
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,