-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public access to prompt()
#30
Comments
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
} |
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 usingnoline
). Can submit pr if wanted.The text was updated successfully, but these errors were encountered: