rustimal 0.8.0

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
//! Telling the person and the programs about things: a command that finished, a pane
//! gaining or losing focus.

use super::*;

/// Tell apps that opted in (CSI ?1004h) about focus changes.
pub(super) fn format_duration(secs: f32) -> String {
    let secs = secs.round() as u32;
    if secs < 60 { format!("{secs}s") } else { format!("{}m {:02}s", secs / 60, secs % 60) }
}

/// Something finished in a pane. If the window is in the background and it took long
/// enough, flash the taskbar button and put what happened in the window title, which is
/// what the taskbar tooltip shows.
pub(super) fn notify_done(st: &mut State, done: Done, threshold: f32) {
    if threshold <= 0.0 || done.secs < threshold || st.window_focused {
        return;
    }
    let took = format_duration(done.secs);
    let what: String = done.what.chars().take(60).collect();
    st.notice = Some(if what == "Claude" {
        format!("✓ Claude is ready · worked {took}")
    } else {
        format!("✓ {what} · finished in {took}")
    });
    st.window.request_user_attention(Some(UserAttentionType::Informational));
    st.window.request_redraw();
}

pub(super) fn notify_focus(st: &State, prev: PaneId) {
    if prev == st.focused {
        return;
    }
    for p in st.panes.iter().filter(|p| p.id == prev || p.id == st.focused) {
        let focused_now = p.id == st.focused && st.window_focused;
        let mut term = p.term.lock();
        term.is_focused = focused_now;
        let report = term.mode().contains(TermMode::FOCUS_IN_OUT);
        drop(term);
        if report {
            p.write(if focused_now { b"\x1b[I".to_vec() } else { b"\x1b[O".to_vec() });
        }
    }
}