statusline 0.23.0

Simple and fast bash PS1 line with useful features
use crate::{Block, Color, Environment, Icon, IconMode, Pretty, Style, WithStyle as _, workgroup};

pub struct Ssh(Vec<String>);

super::register_block!(Ssh);

impl Block for Ssh {
    fn new(_: &Environment) -> Option<Self> {
        let chain = workgroup::chain_open(workgroup::key_load().ok().as_ref());
        (!chain.is_empty()).then_some(Self(chain))
    }
}

impl Icon for Ssh {
    fn icon(&self, mode: IconMode) -> &'static str {
        use IconMode::*;
        match mode {
            Text => "ssh",
            Icons | MinimalIcons => "󰌘",
        }
    }
}

impl Pretty for Ssh {
    fn pretty(&self, f: &mut std::fmt::Formatter<'_>, mode: IconMode) -> std::fmt::Result {
        f.with_style(Color::CYAN, Style::empty(), |f| {
            write!(f, "[{}", self.icon(mode))?;
            for link in &self.0 {
                write!(f, " {link}")?;
            }
            write!(f, "]")
        })
    }
}