diff --git a/Cargo.toml b/Cargo.toml index 4231638..5476980 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,11 @@ version = "0.1.0" edition = "2021" [dependencies] +crossterm = "0.28.1" +ratatui = "0.29.0" +color-eyre = "0.6.3" +#tokio = { version = "1", features = ["full"] } + +[[bin]] +name = "breadm" +path = "src/main.rs" diff --git a/src/main.rs b/src/main.rs index e7a11a9..d56218d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,33 @@ -fn main() { - println!("Hello, world!"); +use color_eyre::Result; +use crossterm::event::{self, Event}; +use ratatui::{DefaultTerminal, Frame}; + +fn render(frame: &mut Frame) { + // Render the "hello world" widget to the terminal using the available area + frame.render_widget("hello world", frame.area()); +} + +fn run(mut terminal: DefaultTerminal) -> Result<()> { + // The main loop + loop { + // Draw the TUI by passing the render function to the terminal's draw method + terminal.draw(render)?; + + // Listen for keypress events + if matches!(event::read()?, Event::Key(_)) { + // Break the loop on key-press and return Ok(()) + break Ok(()); + } + } +} + +fn main() -> Result<()> { + color_eyre::install()?; // Colorful error messages + + let terminal = ratatui::init(); // Initialize the terminal to render the TUI + let result = run(terminal); // The TUI app's main logic. The run() function above. + + ratatui::restore(); // Clear the terminal and return to the previous state + + result // Result of main() }