auraline 0.6.5

utility that renders information into a string suitable to be embedded in the shell prompt.
use smallvec::SmallVec;
use smol_str::{format_smolstr, SmolStr};

use crate::{chunk::Chunk, options::Options};

pub async fn show(opts: &Options) -> Option<Chunk<SmolStr>> {
    if !opts.ssh {
        return None;
    }

    let ssh_connection = std::env::var("SSH_CONNECTION").ok()?;
    let parts = ssh_connection
        .split_whitespace()
        .collect::<SmallVec<[&str; 4]>>();
    if parts.len() >= 4 {
        Some(Chunk::new(
            "⇄",
            format_smolstr!("{}:{}", parts[2], parts[3]),
        ))
    } else {
        None
    }
}