Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: canvas default size #4

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ clone the repo and run `cargo r`
- [x] renaming on gh
- [x] error handling
- [x] publishing to crates.io
- [ ] changing to `Canvas` for rendering viewer block
- [x] changing to `Canvas` for rendering viewer block

## Warning!

Expand All @@ -40,4 +40,4 @@ submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.

[1]: assets/0.2.0_stripes.png "Image of using cgol-cli-rs in Alacritty on Arch Linux"
[1]: assets/0.3.0_stripes.png "Image of using cgol-cli-rs in Alacritty on Arch Linux"
Binary file added assets/0.3.0_stripes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{shapes, Universe, DEF_DUR, DEF_WH};
use crossterm::terminal::size;

use crate::{shapes, Universe, DEF_DUR};
use std::time::Duration;

pub struct App {
Expand All @@ -11,7 +13,8 @@ pub struct App {
impl Default for App {
fn default() -> Self {
let i = 0;
let wh = DEF_WH;
let wh = size().expect("couldn't get terminal size");
let wh = (wh.1 + 10) * 3;
App {
wh,
universe: shapes::get(wh, i).unwrap(),
Expand Down Expand Up @@ -47,8 +50,9 @@ impl App {
pub fn wh(&self) -> u16 {
self.wh
}
pub fn set_wh(&mut self, wh: u16) {
self.wh = wh;
pub fn set_wh(&mut self) {
let wh = size().expect("couldn't get terminal size");
self.wh = (wh.1 + 10) * 3;
}

pub fn play_pause(&mut self, prev_poll_t: &mut Duration) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use ratatui::{style::Color, widgets::canvas::Shape};

use crate::shapes::HandleError;
use std::{fmt, time::Duration};
use std::time::Duration;

/// Default poll duration
pub const DEF_DUR: Duration = Duration::from_millis(400);
/// Default Width and Height
pub const DEF_WH: u16 = 32;
// pub const DEF_WH: u16 = 32;

/// App
pub mod app;
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: &mut App) -> io::Result<
let mut prev_poll_t = app.poll_t();

loop {
let wh = size()?;
app.set_wh((wh.1 + 10) * 3);
app.set_wh();

terminal.draw(|f| ui::ui(f, app))?;

Expand Down Expand Up @@ -91,8 +90,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 + 10) * 3);
app.set_wh();
app.restart();
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::app::App;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
layout::{Constraint, Direction, Layout},
style::{Color, Style},
text::{Line, Span},
widgets::{canvas::Canvas, Block, BorderType, Borders, Paragraph},
widgets::{canvas::Canvas, Block, BorderType, Borders},
Frame,
};

Expand Down
Loading