Initial commit
Some checks failed
CI / fmt (push) Has been cancelled
CI / clippy (push) Has been cancelled
CI / doc (push) Has been cancelled
CI / test macos-latest (push) Has been cancelled
CI / test windows-latest (push) Has been cancelled

This commit is contained in:
2025-09-30 22:07:46 +08:00
commit 80ddea4946
13 changed files with 1061 additions and 0 deletions

61
src/app.rs Normal file
View File

@@ -0,0 +1,61 @@
use crossterm::event;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
use ratatui::{DefaultTerminal, Frame};
use ratatui::style::Stylize;
use ratatui::widgets::{Block, Paragraph};
use ratatui::text::Line;
#[derive(Debug, Default)]
pub struct App {
running: bool,
}
impl App {
pub fn new() -> Self {
Self::default()
}
pub fn run(mut self, mut terminal: DefaultTerminal) -> color_eyre::Result<()> {
self.running = true;
while self.running {
terminal.draw(|frame| self.render(frame))?;
self.handle_input_events()?;
}
Ok(())
}
fn render(&mut self, frame: &mut Frame) {
let title = Line::from("Gal Time Tracker")
.bold()
.blue()
.centered();
let text = "Press `q` to stop running.";
frame.render_widget(
Paragraph::new(text)
.block(Block::bordered().title(title))
.centered(),
frame.area(),
)
}
fn handle_input_events(&mut self) -> color_eyre::Result<()> {
match event::read()? {
// it's important to check KeyEventKind::Press to avoid handling key release events
Event::Key(key) if key.kind == KeyEventKind::Press => self.on_key_event(key),
Event::Mouse(_) => {}
Event::Resize(_, _) => {}
_ => {}
}
Ok(())
}
fn on_key_event(&mut self, key: KeyEvent) {
match (key.modifiers, key.code) {
(_, KeyCode::Char('q')) => self.quit(),
_ => {}
}
}
fn quit(&mut self) {
self.running = false;
}
}

9
src/main.rs Normal file
View File

@@ -0,0 +1,9 @@
mod app;
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let terminal = ratatui::init();
let result = app::App::new().run(terminal);
ratatui::restore();
result
}