futtl 0.2.10

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

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

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

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

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

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

#[test]
fn test_drawing() {
    let mut ctx: FuttlWin = FuttlWin::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 = FuttlWin::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.get_ctx();
    for cell in unsafe { std::slice::from_raw_parts(context.scr_buf, 2) } {
        assert_eq!(cell.c, 0);
        assert_eq!(cell.attributes, Attr::BOLD.bits());
        assert_eq!(cell.cs_idx, 0);
    }
}