Disabling event polling -> Blocking handling
Reduces flickering
This commit is contained in:
parent
1528866d65
commit
4c54639518
1 changed files with 31 additions and 37 deletions
12
src/main.rs
12
src/main.rs
|
@ -1,12 +1,9 @@
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{poll, read, Event, KeyCode},
|
event::{read, Event, KeyCode},
|
||||||
terminal, ExecutableCommand, cursor,
|
terminal, ExecutableCommand, cursor,
|
||||||
};
|
};
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::{
|
use std::io::{stdout, Result, Write, Stdout};
|
||||||
io::{stdout, Result, Write, Stdout},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -37,6 +34,7 @@ fn main() -> Result<()> {
|
||||||
impl Nuudel {
|
impl Nuudel {
|
||||||
|
|
||||||
pub fn run(&mut self, stdout: &mut Stdout) -> Result<()> {
|
pub fn run(&mut self, stdout: &mut Stdout) -> Result<()> {
|
||||||
|
self.draw_terminal(stdout)?;
|
||||||
while !self.quitting {
|
while !self.quitting {
|
||||||
self.handle_events()?;
|
self.handle_events()?;
|
||||||
self.draw_terminal(stdout)?;
|
self.draw_terminal(stdout)?;
|
||||||
|
@ -61,7 +59,6 @@ impl Nuudel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_events(&mut self) -> Result<()> {
|
fn handle_events(&mut self) -> Result<()> {
|
||||||
if poll(Duration::from_secs(0))? {
|
|
||||||
match read()? {
|
match read()? {
|
||||||
Event::Key(event) => match event.code {
|
Event::Key(event) => match event.code {
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => {
|
||||||
|
@ -94,7 +91,6 @@ impl Nuudel {
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,8 +127,6 @@ impl Nuudel {
|
||||||
stdout.execute(cursor::MoveTo(self.cursorx, self.cursory))?;
|
stdout.execute(cursor::MoveTo(self.cursorx, self.cursory))?;
|
||||||
stdout.execute(cursor::Show)?;
|
stdout.execute(cursor::Show)?;
|
||||||
|
|
||||||
std::thread::sleep(Duration::from_millis(16));
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue