ineed 0.1.1

Lightweight CLI prompting library
Documentation
use std::{io, ops::ControlFlow};

use crate::{Promptable, format::Mergeable as _};

/// Wrapper for promptable types to customize the prompt format.
///
/// See the [`Promptable::fmt()`] method for more information.
pub struct Formatted<P: Promptable> {
    pub(crate) prompt: P,
    pub(crate) rules: <P as Promptable>::FmtRules,
}

impl<P: Promptable> Promptable for Formatted<P> {
    type Output = <P as Promptable>::Output;
    type FmtRules = <P as Promptable>::FmtRules;

    fn prompt_once<R, W>(
        &mut self, read: R, write: W, fmt: &Self::FmtRules,
    ) -> io::Result<ControlFlow<Self::Output>>
    where
        R: io::BufRead,
        W: io::Write,
    {
        let fmt = self.rules.merge_with(fmt);
        self.prompt.prompt_once(read, write, &fmt)
    }
}