feat(tui): expand App state with file loading and scroll

This commit is contained in:
dailz
2026-04-10 23:28:23 +08:00
parent 37bebc1a26
commit 555ffc0836
5 changed files with 554 additions and 14 deletions

View File

@@ -11,7 +11,7 @@ struct Cli {
}
fn main() -> anyhow::Result<()> {
let _cli = Cli::parse();
let cli = Cli::parse();
crossterm::terminal::enable_raw_mode()?;
let mut stdout = std::io::stdout();
@@ -21,12 +21,21 @@ fn main() -> anyhow::Result<()> {
let mut app = app::App::new();
if let Some(file) = cli.files.first()
&& let Err(e) = app.load_file(file)
{
eprintln!("Error loading file: {e}");
std::process::exit(1);
}
while !app.should_quit {
terminal.draw(|frame| ui::render(frame, &app))?;
if crossterm::event::poll(std::time::Duration::from_millis(100))?
&& let crossterm::event::Event::Key(key) = crossterm::event::read()?
{
app.handle_key(key);
if crossterm::event::poll(std::time::Duration::from_millis(100))? {
match crossterm::event::read()? {
crossterm::event::Event::Key(key) => app.handle_key(key),
crossterm::event::Event::Resize(_w, _h) => {}
_ => {}
}
}
}