Skip to content
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

Open
bluespider42 opened this issue Nov 5, 2024 · 5 comments
Open

Public access to prompt() #30

bluespider42 opened this issue Nov 5, 2024 · 5 comments

Comments

@bluespider42
Copy link

bluespider42 commented Nov 5, 2024

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);
    }
@thejpster
Copy link
Member

Seems reasonable, but doesn't the prompt print automatically?

@bluespider42
Copy link
Author

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);

@thejpster
Copy link
Member

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.

@bluespider42
Copy link
Author

That would be a neater solution.

@bluespider42
Copy link
Author

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
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants