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 hts_sets_custom_tab_stop() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    // Clear all tabs, move to col 5, set tab, go back, tab forward
    process(&mut parser, b"\x1b[3g\x1b[6G\x1bH\x1b[1G\t");
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 5 });
}

#[test]
fn tbc_clears_at_cursor() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    // Move to col 8 (default tab stop), clear it, go back, tab forward
    process(&mut parser, b"\x1b[9G\x1b[0g\x1b[1G\t");
    // Should skip col 8 and go to col 16
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 16 });
}

#[test]
fn tbc_clears_all() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b[3g\t");
    // No tab stops, should go to last column
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 79 });
}

#[test]
fn cht_forward_n() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    // CHT 3 = forward 3 tab stops
    process(&mut parser, b"\x1b[3I");
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 24 });
}

#[test]
fn cbt_backward() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b[21G\x1b[Z");
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 16 });
}

#[test]
fn cbt_backward_n() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    process(&mut parser, b"\x1b[21G\x1b[2Z");
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 8 });
}

#[test]
fn tab_stops_reset_by_ris() {
    let mut parser = crate::Parser::new(TerminalSize { rows: 24, cols: 80 }, 0);
    // Clear all tabs, then RIS, then tab should work at default stops
    process(&mut parser, b"\x1b[3g\x1bc\t");
    assert_eq!(parser.screen().cursor(), Position { row: 0, col: 8 });
}