tastty-core 0.1.0

Sans-IO core of the tastty terminal session library: VT parser, screen buffer, and byte encoders.
use super::*;

#[test]
fn custom_da1_response() {
    let profile = crate::HostProfile {
        da1: b"\x1b[?64;22c".to_vec(),
        ..Default::default()
    };
    let mut parser = crate::Parser::with_profile(
        TerminalSize { rows: 24, cols: 80 },
        0,
        std::sync::Arc::new(profile),
    );
    process(&mut parser, b"\x1b[c");
    assert_eq!(drain_replies(&mut parser), b"\x1b[?64;22c");
}

#[test]
fn custom_xtversion_name() {
    let profile = crate::HostProfile {
        xtversion_name: "myterm(1.0)".to_string(),
        ..Default::default()
    };
    let mut parser = crate::Parser::with_profile(
        TerminalSize { rows: 24, cols: 80 },
        0,
        std::sync::Arc::new(profile),
    );
    process(&mut parser, b"\x1b[>q");
    let raw = drain_replies(&mut parser);
    let resp = String::from_utf8_lossy(&raw);
    assert!(resp.contains("myterm(1.0)"));
}

#[test]
fn custom_terminfo_name_in_xtgettcap() {
    let profile = crate::HostProfile {
        terminfo_name: "myterm".to_string(),
        ..Default::default()
    };
    let mut parser = crate::Parser::with_profile(
        TerminalSize { rows: 24, cols: 80 },
        0,
        std::sync::Arc::new(profile),
    );
    // TN in hex: 544E
    process(&mut parser, b"\x1bP+q544E\x1b\\");
    let raw = drain_replies(&mut parser);
    // "myterm" hex-encoded: 6D797465726D
    let resp_str = String::from_utf8_lossy(&raw);
    assert!(resp_str.contains("6D797465726D"), "got: {resp_str}");
}

#[test]
fn host_profile_sets_default_colors() {
    use crate::attrs::Color;
    let profile = crate::HostProfile {
        default_fg: Color::Rgb(10, 20, 30),
        default_bg: Color::Rgb(40, 50, 60),
        ..Default::default()
    };
    let parser = crate::Parser::with_profile(
        TerminalSize { rows: 24, cols: 80 },
        0,
        std::sync::Arc::new(profile),
    );
    assert_eq!(
        parser.screen().default_fg,
        Color::Rgb(10, 20, 30),
        "HostProfile.default_fg must seed Screen.default_fg at construction",
    );
    assert_eq!(
        parser.screen().default_bg,
        Color::Rgb(40, 50, 60),
        "HostProfile.default_bg must seed Screen.default_bg at construction",
    );
}

#[test]
fn ris_preserves_host_profile_defaults() {
    use crate::attrs::Color;
    let profile = crate::HostProfile {
        default_fg: Color::Rgb(1, 2, 3),
        default_bg: Color::Rgb(4, 5, 6),
        default_cursor_color: Color::Rgb(7, 8, 9),
        ..Default::default()
    };
    let mut parser = crate::Parser::with_profile(
        TerminalSize { rows: 24, cols: 80 },
        0,
        std::sync::Arc::new(profile),
    );
    assert_eq!(parser.screen().default_fg, Color::Rgb(1, 2, 3));
    assert_eq!(parser.screen().default_bg, Color::Rgb(4, 5, 6));
    assert_eq!(parser.screen().default_cursor_color, Color::Rgb(7, 8, 9));

    process(&mut parser, b"\x1bc");

    assert_eq!(
        parser.screen().default_fg,
        Color::Rgb(1, 2, 3),
        "RIS must reset palette state but preserve the host profile's default fg",
    );
    assert_eq!(
        parser.screen().default_bg,
        Color::Rgb(4, 5, 6),
        "RIS must reset palette state but preserve the host profile's default bg",
    );
    assert_eq!(
        parser.screen().default_cursor_color,
        Color::Rgb(7, 8, 9),
        "RIS must reset palette state but preserve the host profile's default cursor color",
    );
}