rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
//! What can be put over a pane in place of its terminal.

/// Something that can be put over a pane in place of its terminal. Whatever is added here
/// is switched to and from by the same key.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Embed {
    /// A web app in a view of its own.
    Web(WebKind),
    /// The `do` conversation.
    Chat,
    /// The review panel.
    Review,
    /// A program's own window, taken into the pane.
    Host,
}

/// What a pane has open over its terminal, shown or not, the latest shown last.
#[derive(Default, Debug)]
pub struct Embeds(Vec<Embed>);

impl Embeds {
    pub fn shown(&mut self, embed: Embed) {
        self.closed(embed);
        self.0.push(embed);
    }

    pub fn closed(&mut self, embed: Embed) {
        self.0.retain(|&e| e != embed);
    }

    /// The one to bring back.
    pub fn latest(&self) -> Option<Embed> {
        self.0.last().copied()
    }
}

/// Which web app a view in a pane shows.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum WebKind {
    T3,
    Code,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn the_latest_thing_over_a_pane_is_the_one_to_bring_back() {
        let (t3, code, chat) = (Embed::Web(WebKind::T3), Embed::Web(WebKind::Code), Embed::Chat);
        let mut open = Embeds::default();
        assert_eq!(open.latest(), None);
        open.shown(t3);
        open.shown(code);
        assert_eq!(open.latest(), Some(code));
        open.shown(t3);
        assert_eq!(open.latest(), Some(t3), "shown again, it is the latest");
        open.closed(t3);
        assert_eq!(open.latest(), Some(code), "closing falls back to the one before");
        open.shown(chat);
        open.closed(code);
        assert_eq!(open.latest(), Some(chat));
        open.closed(chat);
        assert_eq!(open.latest(), None);
    }
}