rho-coding-agent 3.8.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Nerd Font file-type icons drawn before linked paths when icons are on.
//!
//! Every glyph comes from a range Nerd Fonts has kept since 2.x (Seti,
//! Devicons, Font Awesome 4), so the older symbol fonts that WezTerm
//! 20220319 bundled draw them too. Each is one cell wide, as
//! `unicode-width` and the symbols' Mono builds agree. An icon is followed
//! by a no-break space, which wrapping never breaks at, so the icon stays on
//! its path's row; copy skips the pair (see [`is_icon_run`]).

/// What follows an icon: wrapping keeps it with the path.
const ICON_GAP: char = '\u{a0}';

/// Fallback for a file of no listed type: `nf-fa-file_o`.
const FILE: char = '\u{f016}';

/// The icon for a file named `name`.
fn file_icon(name: &str) -> char {
    let lower = name.to_ascii_lowercase();
    match lower.as_str() {
        ".gitignore" | ".gitattributes" | ".gitmodules" | ".gitkeep" => return '\u{e702}', // nf-dev-git
        "package-lock.json" | "pnpm-lock.yaml" => return '\u{f023}', // nf-fa-lock
        _ => {}
    }
    let Some((_, extension)) = lower.rsplit_once('.') else {
        return FILE;
    };
    match extension {
        "rs" => '\u{e7a8}',                                             // nf-dev-rust
        "ts" | "tsx" | "mts" | "cts" => '\u{e628}',                     // nf-seti-typescript
        "js" | "jsx" | "mjs" | "cjs" => '\u{e60c}',                     // nf-seti-javascript
        "py" | "pyi" => '\u{e606}',                                     // nf-seti-python
        "md" | "mdx" | "markdown" => '\u{e609}',                        // nf-seti-markdown
        "json" | "jsonc" | "json5" => '\u{e60b}',                       // nf-seti-json
        "toml" | "yaml" | "yml" | "ini" | "cfg" | "conf" => '\u{e615}', // nf-seti-config
        "sh" | "bash" | "zsh" | "fish" => '\u{e795}',                   // nf-dev-terminal
        "lock" => '\u{f023}',                                           // nf-fa-lock
        "png" | "jpg" | "jpeg" | "gif" | "svg" | "webp" | "ico" | "bmp" => '\u{f1c5}', // nf-fa-file_image_o
        _ => FILE,
    }
}

/// The run drawn before a linked path: its icon and the gap after it.
pub(super) fn icon_run_text(name: &str) -> String {
    format!("{}{ICON_GAP}", file_icon(name))
}

/// Whether `text` is an icon run as [`icon_run_text`] makes it, which a
/// copy of transcript text leaves out so the path copies as written.
pub(in crate::tui) fn is_icon_run(text: &str) -> bool {
    let mut chars = text.chars();
    matches!(
        (chars.next(), chars.next(), chars.next()),
        (Some(icon), Some(ICON_GAP), None) if is_private_use(icon)
    )
}

/// Whether `ch` is in the Basic Multilingual Plane's private use area,
/// where every icon here sits.
fn is_private_use(ch: char) -> bool {
    ('\u{e000}'..='\u{f8ff}').contains(&ch)
}