Public access to `prompt()`
In version 0.6 self.prompt() has moved inside the inner_runner which is not public. It was useful to have access to .prompt() to display the prompt after printing any information so that the user knows it is ready for input.
Adding this to the runner impl is working for my purposes (not currently using noline). Can submit pr if wanted.
pub fn prompt(&mut self, newline:bool) {
self.inner.prompt(&mut self.interface, newline);
}
Seems reasonable, but doesn't the prompt print automatically?
I guess if all the logic is handled within a command callback then yes. I find it useful to be able to send arbitrary messages, particularly from long running tasks. Unless I am missing the intended use.
write!(runner.interface, "My Message - Result = {}", val);
Ah, yes, mixing indications with command/response is always interesting. That kind of print might mix badly if the user is currently typing a command. Maybe we should offer a function that takes a closure, like:
menu.print_indication(|w| {
writeln!(w, "+RING");
});
// When the closure ends, the prompt and the current command-line will be re-drawn.
That would be a neater solution.
As a first attempt, this is working for my purposes.
pub fn print_indication<F, G>(&mut self, f: F) -> G
where
F: Fn(&mut I) -> G,
{
let g = f(&mut self.interface);
let buffer = self.buffer.as_mut();
if let Ok(s) = core::str::from_utf8(&buffer[0..self.used]) {
write!(self.interface, "\r").unwrap();
self.inner.prompt(&mut self.interface, false);
write!(self.interface, "{}", s).unwrap();
}
g
}