#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(jinux_frame::test_runner)]
#![reexport_test_harness_main = "test_main"]
extern crate alloc;
use core::panic::PanicInfo;
use jinux_frame::println;

static mut INPUT_VALUE: u8 = 0;

#[no_mangle]
pub fn jinux_main() -> ! {
    jinux_frame::init();
    test_main();
    loop {}
}

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    jinux_frame::test_panic_handler(info)
}

#[test_case]
fn test_input() {
    x86_64::instructions::interrupts::enable();
    println!("please input value into console to pass this test");
    // FIXME: Where is tty?
    // jinux_std::driver::tty::register_serial_input_callback(input_callback);
    unsafe {
        while INPUT_VALUE == 0 {
            x86_64::instructions::hlt();
        }
        // println!("input value:{}", INPUT_VALUE);
    }
}

pub fn input_callback(input: u8) {
    println!("input value:{}", input);
    unsafe {
        INPUT_VALUE = input;
    }
}
