fn run_with<R: BufRead, W: Write>(
    // The message/title displayed on the top.
    msg: Option<&str>,
    // The stream used by the menu.
    stream: &mut MenuStream<R, W>,
    // The fields of the current prompted menu.
    fields: Fields<R, W>,
    // The formatting specifications used by the menu.
    fmt: &Format<'_>,
) -> MenuResult<Option<usize>> {
    loop {
        // Title of current selective menu.
        if let Some(s) = msg {
            writeln!(stream, "{}", s)?;
        }

        // Fields of current selective menu.
        for (i, (field_msg, _)) in fields.iter().enumerate() {
            writeln!(stream, "{}{}{}", i + 1, fmt.chip, field_msg)?;
        }

        // Gets the message and the field kind selected by the user.
        let (msg, kind) = loop {
            match select(stream, fmt.suffix, fields.len())?.and_then(|i| fields.get(i)) {
                Some(field) => break field,
                None => continue,
            }
        };

        match kind {
            Kind::Map(f) => return f(stream).map(|_| None),
            Kind::Parent(fields) => match run_with(Some(msg), stream, fields, fmt)? {
                None => return Ok(None),
                Some(0) => continue,
                Some(i) => return Ok(Some(i - 1)),
            },
            Kind::Back(0) => continue,
            Kind::Back(i) => return Ok(Some(i - 1)),
            Kind::Quit => return Ok(None),
        }
    }
}
/// Recursive function used to run the current prompt state of the menu.
///
/// It prints out to the stream the fields next to their indexes, then asks the user to
/// select a field. Then, it runs the corresponding procedure matching the selected field kind.
///
/// The function returns a wrapped `Option<usize>`. The index inside corresponds to the current
/// level of depth of the menu. With recursion, it allows to go back to the indexed depth
/// level from the current running prompt.
// FIXME: Replace the recursive function by a regular function.
Recursive function used to run the current prompt state of the menu.
It prints out to the stream the fields next to their indexes, then asks the user to
select a field. Then, it runs the corresponding procedure matching the selected field kind.

The function returns a wrapped `Option`. The index inside corresponds to the current
level of depth of the menu. With recursion, it allows to go back to the indexed depth
level from the current running prompt.
FIXME: Replace the recursive function by a regular function.
Recursive function used to run the current prompt state of the menu . It prints out to the stream the fields next to their indexes then asks the user to select a field . Then it runs the corresponding procedure matching the selected field kind . The function returns a wrapped ` Option ` . The index inside corresponds to the current level of depth of the menu . With recursion it allows to go back to the indexed depth level from the current running prompt . FIXME : Replace the recursive function by a regular function .
fn run_with<R: BufRead, W: Write>(
    // The message/title displayed on the top.
    msg: Option<&str>,
    // The stream used by the menu.
    stream: &mut MenuStream<R, W>,
    // The fields of the current prompted menu.
    fields: Fields<R, W>,
    // The formatting specifications used by the menu.
    fmt: &Format<'_>,
) -> MenuResult<Option<usize>> {
    loop {
        // Title of current selective menu.
        if let Some(s) = msg {
            writeln!(stream, "{}", s)?;
        }
        // Fields of current selective menu.
        for (i, (field_msg, _)) in fields.iter().enumerate() {
            writeln!(stream, "{}{}{}", i + 1, fmt.chip, field_msg)?;
        }
        // Gets the message and the field kind selected by the user.
        let (msg, kind) = loop {
            match select(stream, fmt.suffix, fields.len())?.and_then(|i| fields.get(i)) {
                Some(field) => break field,
                None => continue,
            }
        };
        match kind {
            Kind::Map(f) => return f(stream).map(|_| None),
            Kind::Parent(fields) => match run_with(Some(msg), stream, fields, fmt)? {
                None => return Ok(None),
                Some(0) => continue,
                Some(i) => return Ok(Some(i - 1)),
            },
            Kind::Back(0) => continue,
            Kind::Back(i) => return Ok(Some(i - 1)),
            Kind::Quit => return Ok(None),
        }
    }
}
fn run_with < R : BufRead , W : Write > ( // The message/title displayed on the top. msg : Option < & str > , // The stream used by the menu. stream : & mut MenuStream < R , W > , // The fields of the current prompted menu. fields : Fields < R , W > , // The formatting specifications used by the menu. fmt : & Format < ' _ > , ) -> MenuResult < Option < usize > > { loop { // Title of current selective menu. if let Some ( s ) = msg { writeln ! ( stream " " s ) ? ; } // Fields of current selective menu. for ( i , ( field_msg , _ ) ) in fields . iter ( ) . enumerate ( ) { writeln ! ( stream " " i 1 fmt chip field_msg ) ? ; } // Gets the message and the field kind selected by the user. let ( msg , kind ) = loop { match select ( stream , fmt . suffix , fields . len ( ) ) ? . and_then ( | i | fields . get ( i ) ) { Some ( field ) => break field , None => continue , } } ; match kind { Kind :: Map ( f ) => return f ( stream ) . map ( | _ | None ) , Kind :: Parent ( fields ) => match run_with ( Some ( msg ) , stream , fields , fmt ) ? { None => return Ok ( None ) , Some ( 0 ) => continue , Some ( i ) => return Ok ( Some ( i - 1 ) ) , } , Kind :: Back ( 0 ) => continue , Kind :: Back ( i ) => return Ok ( Some ( i - 1 ) ) , Kind :: Quit => return Ok ( None ) , } } }
Recursive function used to run the current prompt state of the menu.
Recursive function used to run the current prompt state of the menu .
msg
Option<&str>
stream
&mut MenuStream<R, W>
fields
Fields<R, W>
fmt
&Format<'_>