Skip to content

Commit

Permalink
Flush resize event from startup + address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentFoulon80 committed Aug 22, 2022
1 parent 55617eb commit b819c29
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
authors = ["Vincent Foulon <[email protected]>"]
categories = ["command-line-interface"]
description = "A simple terminal framework to draw things and manage user input"
edition = "2021"
include = ["src/**/*", "LICENSE", "README.md"]
Expand All @@ -8,7 +9,7 @@ license = "MIT"
name = "console_engine"
readme = "README.md"
repository = "https://github.com/VincentFoulon80/console_engine"
version = "2.5.0"
version = "2.5.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
Expand Down
4 changes: 2 additions & 2 deletions src/forms/constraints/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ impl FormConstraint for Integer {
return false;
}
if let Some(chr) = value.chars().next() {
if !chr.is_digit(10) && chr != '-' && chr != '+' {
if !chr.is_ascii_digit() && chr != '-' && chr != '+' {
return false;
}
}
value.chars().skip(1).all(|x| x.is_digit(10))
value.chars().skip(1).all(|x| x.is_ascii_digit())
}
FormValue::Map(entries) => entries.iter().all(|(_, x)| self.validate(x)),
FormValue::List(entries) => entries
Expand Down
4 changes: 2 additions & 2 deletions src/forms/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Text {
}
self.dirty = true;
let off_l = amount.max(0) as usize; // offset to the left from cursor, `positive` or 0
let off_r = amount.min(0).abs() as usize; // offset to the right from cursor, `-negative` or 0
let off_r = amount.min(0).unsigned_abs() as usize; // offset to the right from cursor, `-negative` or 0
let pos_l = self.cursor_pos.saturating_sub(off_l);
let pos_r = self
.cursor_pos
Expand Down Expand Up @@ -270,7 +270,7 @@ impl HiddenText {
}
self.dirty = true;
let off_l = amount.max(0) as usize; // offset to the left from cursor, `positive` or 0
let off_r = amount.min(0).abs() as usize; // offset to the right from cursor, `-negative` or 0
let off_r = amount.min(0).unsigned_abs() as usize; // offset to the right from cursor, `-negative` or 0
let pos_l = self.cursor_pos.saturating_sub(off_l);
let pos_r = self
.cursor_pos
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ impl ConsoleEngine {
crossterm::terminal::SetSize(width as u16, height as u16)
)?;
self.resize(width, height);
// flush events
#[cfg(feature = "event")]
use std::time::Duration;
#[cfg(feature = "event")]
while let Ok(true) = event::poll(Duration::from_micros(100)) {
event::read().ok();
}
}
if crossterm::terminal::size()? < (width as u16, height as u16) {
Err(ErrorKind::new(std::io::ErrorKind::Other, format!("Your terminal must have at least a width and height of {}x{} characters. Currently has {}x{}", width, height, size.0, size.1)))
Expand Down
6 changes: 3 additions & 3 deletions src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl Screen {
}
}
} else {
let step = h_scroll.abs() as usize;
let step = h_scroll.unsigned_abs() as usize;
// scroll to the right
for j in 0..height {
// move the pixels
Expand Down Expand Up @@ -813,8 +813,8 @@ impl Screen {
end_y: i32,
default: Pixel,
) -> Screen {
let target_width = (end_x - start_x).abs() as u32 + 1;
let target_height = (end_y - start_y).abs() as u32 + 1;
let target_width = (end_x - start_x).unsigned_abs() + 1;
let target_height = (end_y - start_y).unsigned_abs() + 1;
let mut extracted_screen = vec![default; (target_width * target_height) as usize];
let x_reversed = start_x > end_x;
let y_reversed = start_y > end_y;
Expand Down

0 comments on commit b819c29

Please sign in to comment.