From 3f65df6be1536e740541361d61c25d91cc2dc298 Mon Sep 17 00:00:00 2001 From: Jeromos Kovacs Date: Thu, 29 Feb 2024 20:50:11 +0100 Subject: [PATCH] fix(code): removed unneeded comments, added some where needed, written acknowledgements to README.md --- README.md | 4 ++++ src/app.rs | 4 ++-- src/lib.rs | 2 ++ src/main.rs | 12 ++++-------- src/ui.rs | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 552e6e9..ef4f105 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ clone the repo and run `cargo r` - [x] error handling - [x] publishing to crates.io +## Acknowledgements + +The core of this app is adapted from the great [Rust-Wasm tutorial](https://rustwasm.github.io/docs/book/). + ## License Licensed under either of diff --git a/src/app.rs b/src/app.rs index e0ae27a..f38e074 100644 --- a/src/app.rs +++ b/src/app.rs @@ -100,7 +100,7 @@ impl App { if let Ok(shape) = shapes::get(self.wh(), self.i) { self.universe = shape; } else { - eprintln!("couldn't switch to next shape\r"); + eprintln!("couldn't switch to next shape"); } } pub fn prev(&mut self) { @@ -112,7 +112,7 @@ impl App { if let Ok(shape) = shapes::get(self.wh(), self.i) { self.universe = shape; } else { - eprintln!("couldn't switch to previous shape\r"); + eprintln!("couldn't switch to previous shape"); } } } diff --git a/src/lib.rs b/src/lib.rs index 015cbc3..ce656cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,6 +177,7 @@ impl Universe { self.height } + // unused /// toggles cell at (`row`;`col`) pub fn toggle_cell(&mut self, row: u16, col: u16) { let idx = self.get_index(row, col); @@ -199,6 +200,7 @@ impl Universe { // Ok(()) // } // } + impl fmt::Display for Universe { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for line in self.cells.as_slice().chunks(self.width as usize) { diff --git a/src/main.rs b/src/main.rs index 698d14d..3fc017c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,24 +13,20 @@ use ratatui::{ use std::io; fn main() -> Result<(), Box> { + // init terminal enable_raw_mode()?; execute!(io::stdout(), EnterAlternateScreen)?; let backend = CrosstermBackend::new(io::stdout()); let mut terminal = Terminal::new(backend)?; - // create app and run it + // create app and run it with width and height from terminal size let wh = size()?; let mut app = App::new(wh.1 - 4); - // app.set_width(wh.0 + 3); - // app.set_height(wh.1 - 3); - // app.set_wh(wh.1 + 1 - 5); - // app.set_height(38); - // app.set_width(DEF_WH + 2); - // app.set_height(DEF_WH + 2); let res = run_app(&mut terminal, &mut app); + // reset terminal disable_raw_mode()?; execute!(terminal.backend_mut(), LeaveAlternateScreen)?; terminal.show_cursor()?; @@ -38,7 +34,6 @@ fn main() -> Result<(), Box> { if let Err(err) = res { println!("Error: {err:?}"); } - eprintln!("initial size was: {wh:?}"); Ok(()) } @@ -83,6 +78,7 @@ fn run_app(terminal: &mut Terminal, app: &mut App) -> io::Result< _ => {} } } else { + // resize and restart let wh = size()?; app.set_wh(wh.1 + 1 - 5); app.restart(); diff --git a/src/ui.rs b/src/ui.rs index 4e075af..bb056e4 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -16,7 +16,7 @@ pub fn ui(f: &mut Frame, app: &App) { // |____________________| let chunks = Layout::default() .direction(Direction::Vertical) - .constraints([Constraint::Min(4), Constraint::Length(1)]) + .constraints([Constraint::Min(0), Constraint::Length(1)]) .split(f.size()); // let current_shape = shapes::get(app.wh, app.i()).unwrap();