[][src]Struct shli::prompt::Prompt

pub struct Prompt {
    pub prompt_text: String,
    pub history: Vec<String>,
    pub commands: Vec<Command>,
}

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: Stringhistory: 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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.