ulyssa / modalkit

A Rust library for building modal editing applications
Apache License 2.0
49 stars 5 forks source link

Support interactive dialog at the bottom of the screen #83

Closed ulyssa closed 1 year ago

ulyssa commented 1 year ago

I'm not sure what this looks like yet, but there's not currently a way to ask for simple user input in the way that Vim does when using features like the c flag for substitutions, or the :confirm command. Given that a lot of these happen in the middle of doing work, I wonder if it should be a UIError. Maybe something like:

pub trait Dialog<I>
where
    I: ApplicationInfo,
{
    /// Message to show to users, such as "Quit? (y/N)"
    fn message(&self) -> String;

    /// How many characters to read from the user before calling input().
    fn input_max(&self) -> usize;

    /// The user's response to this interactive dialog. The user will be repeatedly
    /// prompted until this returns Some.
    fn input(&mut self, s: &str) -> Option<Action<I>>;
}

pub enum UIError<I>
where
    I: ApplicationInfo,
{
    ...
    NeedConfirm(Box<dyn Dialog>),
}