#[cfg(feature = "tui")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    use std::thread;
    use std::time::Duration;

    use kcan::{CanFrame, CanId, TuiCanMonitor};
    use scrin::{Terminal, TerminalOptions};

    let mut monitor = TuiCanMonitor::sample()?;
    let mut terminal = Terminal::init_with(TerminalOptions::new())?;

    for tick in 0..90_u8 {
        monitor.advance_tick();
        monitor.observe(CanFrame::new(
            CanId::extended(0x400 + u32::from((tick % 4) + 1))?,
            &[tick, tick.wrapping_add(1), 0xAA, 0x55],
        )?);
        terminal.draw(|frame| monitor.render_frame(frame))?;
        thread::sleep(Duration::from_millis(50));
    }

    terminal.restore()?;
    Ok(())
}

#[cfg(not(feature = "tui"))]
fn main() {
    eprintln!("enable the `tui` feature to run this example");
}
