Skip to content

Commit

Permalink
fix(code): removed unneeded comments, added some where needed, writte…
Browse files Browse the repository at this point in the history
…n acknowledgements to README.md
  • Loading branch information
JeromeSchmied committed Feb 29, 2024
1 parent 67b15f9 commit 3f65df6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
}
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
12 changes: 4 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,27 @@ use ratatui::{
use std::io;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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()?;

if let Err(err) = res {
println!("Error: {err:?}");
}
eprintln!("initial size was: {wh:?}");

Ok(())
}
Expand Down Expand Up @@ -83,6 +78,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: &mut App) -> io::Result<
_ => {}
}
} else {
// resize and restart
let wh = size()?;
app.set_wh(wh.1 + 1 - 5);
app.restart();
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3f65df6

Please sign in to comment.