65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
mod action;
|
|
mod highlight;
|
|
mod lang;
|
|
mod state;
|
|
mod terminal;
|
|
mod theme;
|
|
mod ui;
|
|
|
|
use crate::{
|
|
action::{Action, Dir, Dist, Event, MouseAction},
|
|
state::State,
|
|
terminal::{Area, Color, Terminal, TerminalEvent},
|
|
ui::{Element as _, Visual as _},
|
|
};
|
|
use clap::Parser;
|
|
use std::{io, path::PathBuf, time::Duration};
|
|
|
|
#[derive(Parser, Debug)]
|
|
struct Args {
|
|
paths: Vec<PathBuf>,
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum Error {
|
|
#[error("io: {0}")]
|
|
Io(#[from] io::Error),
|
|
#[error("no such buffer")]
|
|
NoSuchBuffer,
|
|
}
|
|
|
|
fn main() -> Result<(), Error> {
|
|
let args = Args::parse();
|
|
|
|
let mut state = State::try_from(args)?;
|
|
let open_buffers = state.buffers.keys().collect::<Vec<_>>();
|
|
let mut ui = ui::Root::new(&mut state, &open_buffers);
|
|
|
|
Terminal::with(move |term| {
|
|
loop {
|
|
// Render the state to the screen
|
|
term.update(|fb| ui.render(&state, fb));
|
|
|
|
// Wait for a while
|
|
term.wait_at_least(Duration::from_millis(250));
|
|
|
|
while let Some(ev) = term.get_event() {
|
|
// Resize events are special and need handling by the terminal
|
|
if let TerminalEvent::Resize(cols, rows) = ev {
|
|
term.set_size([cols, rows]);
|
|
}
|
|
|
|
// Have the UI handle events
|
|
match ui.handle(&mut state, Event::from_raw(ev)) {
|
|
Ok(r) if r.is_end() => return Ok(()),
|
|
Ok(_) => {}
|
|
Err(Event::Bell) => term.ring_bell(),
|
|
// Unhandled event!
|
|
Err(_) => {}
|
|
}
|
|
}
|
|
|
|
state.tick();
|
|
}
|
|
})
|
|
}
|