[−][src]Function shli::input::read_commandline
pub fn read_commandline(
stdin: StdinLock,
stdout: &mut Stdout,
completion: impl Fn(&str) -> Vec<String>
) -> Result<Vec<String>>
Prompt for a single command line.
This function reads and returns a command line, after prompting with >
.
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"]
.