use tb_runtime::host::{CaptureHost, Ereignis, MausArt, MausEreignis};
use tb_vm::interp::{RunEvent, Vm};

fn main() {
    let form = tb_ui::frm::read_text(
        "eingabe-taste-maus.frm",
        include_str!("../../compat/eingabe-taste-maus.frm"),
    )
    .unwrap();
    let module = tb_vm::compile_source_with_forms("FORM1", &form.code, &form.catalog()).unwrap();
    let mut vm = Vm::new(module);
    form.apply(&mut vm.forms).unwrap();
    vm.forms.show(0, false).unwrap();
    let mut host = CaptureHost::default();
    host.ereignis_nach(2, Ereignis::Taste("K".into(), 0));
    host.ereignis_nach(
        2,
        Ereignis::Maus(MausEreignis {
            art: MausArt::Druck,
            taste: 1,
            shift: 0,
            zeile: 2,
            spalte: 2,
        }),
    );
    assert_eq!(vm.run(&mut host), RunEvent::Ended);
    assert_eq!(tb_runtime::snapshot::text(&vm.rt.screen), "KM\n");
    println!("Terminalfreier FRM-/VM-Lauf: KM");
}
