futtl 0.4.0

Rust bindings for the FUTTL terminal UI library
use crate::Attr;
use crate::Futtl;
use crate::Win;

#[test]
fn test_init() {
    let mut ctx: Win = Win::new(1, Attr::NONE);

    assert_eq!(ctx.ctx().has_init, 1);
}

#[test]
fn test_box_init() {
    let mut ctx: Win = Win::new(1, Attr::NONE);

    let _child: usize = ctx.create_container(10, 5);

    assert_eq!(ctx.ctx().child_count, 1);
}

#[test]
fn test_drawing() {
    let mut ctx: Win = Win::new(1, Attr::NONE);

    ctx.set_curs(0, 0);

    ctx.write_str("Hello");

    ctx.show();
}

#[test]
fn test_clear_resets_every_cell_color() {
    let mut ctx = Win::new(2, Attr::BOLD);

    ctx.set_curs(0, 0);
    ctx.set_color(1);
    ctx.put_char('x');
    ctx.set_curs(1, 0);
    ctx.set_color(1);
    ctx.put_char('y');

    ctx.clear();

    let context = ctx.ctx();
    for cell in unsafe { std::slice::from_raw_parts(context.scr_buf, 2) } {
        assert_eq!(cell.c, ' ' as u32);
        assert_eq!(cell.attributes, Attr::BOLD.bits());
        assert_eq!(cell.cs_idx, 0);
    }
}