/// RFC 01 验收 example
///
/// 假设框架已有：
/// - `Buffer::new(size)` — 创建缓冲区
/// - `Buffer::write_text(pos, clip, text, style)` — 写入文本
/// - `Buffer::diff(&next) -> Vec<DiffOp>` — 计算差异
/// - `CrosstermBackend::flush(ops)` — 刷新到终端

use lv_tui::backend::{CrosstermBackend, TerminalBackend};
use lv_tui::buffer::Buffer;
use lv_tui::geom::{Pos, Rect};
use lv_tui::style::Style;

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

    // 进入终端
    backend.enter()?;
    let size = backend.size()?;

    // 创建 front/back buffer
    let front = Buffer::new(size);
    let mut back = Buffer::new(size);

    // 写入 back buffer
    let clip = Rect {
        x: 0,
        y: 0,
        width: size.width,
        height: size.height,
    };
    back.write_text(
        Pos { x: 0, y: 0 },
        clip,
        "hello lv-tui",
        &Style::default(),
    );

    // diff 并 flush
    let ops = front.diff(&back);
    backend.flush(&ops)?;

    // 等待按键后退出
    backend.read_event()?;

    backend.leave()?;
    Ok(())
}
