/// Phase 0 验收程序
///
/// 验证终端后端可以：
/// - 进入/退出 raw mode + alternate screen
/// - 读取按键事件
/// - 按 q 退出
/// - panic 时终端状态恢复

use lv_tui::backend::{CrosstermBackend, TerminalBackend};
use lv_tui::event::{Event, Key};

fn main() -> lv_tui::Result<()> {
    let mut backend = CrosstermBackend::new()?;

    backend.enter()?;
    println!("Terminal backend entered. Press 'q' to quit.");

    loop {
        let event = backend.read_event()?;

        if let Event::Key(key_event) = &event {
            println!("Key pressed: {:?}", key_event.key);
        }

        if event.is_key(Key::Char('q')) {
            break;
        }
    }

    backend.leave()?;
    println!("Terminal restored. Goodbye!");

    Ok(())
}
