Return Redraw enum instead of bool
Boolean values were too easy to accidentally interpret the wrong way.
This commit is contained in:
parent
3b2ea37ba5
commit
8fae7d2bf1
3 changed files with 51 additions and 31 deletions
|
|
@ -1,8 +1,7 @@
|
|||
use std::io;
|
||||
|
||||
use crossterm::event::Event;
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use toss::frame::{Frame, Pos};
|
||||
use toss::terminal::Terminal;
|
||||
use toss::terminal::{Redraw, Terminal};
|
||||
|
||||
fn draw(f: &mut Frame) {
|
||||
f.write(
|
||||
|
|
@ -18,24 +17,32 @@ fn draw(f: &mut Frame) {
|
|||
f.show_cursor(Pos::new(16, 0));
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
// Automatically enters alternate screen and enables raw mode
|
||||
let mut term = Terminal::new()?;
|
||||
|
||||
fn render_frame(term: &mut Terminal) {
|
||||
loop {
|
||||
// Must be called before rendering, otherwise the terminal has out-of-date
|
||||
// size information and will present garbage.
|
||||
term.autoresize()?;
|
||||
term.autoresize().unwrap();
|
||||
|
||||
draw(term.frame());
|
||||
|
||||
if !term.present()? {
|
||||
if term.present().unwrap() == Redraw::NotRequired {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Automatically enters alternate screen and enables raw mode
|
||||
let mut term = Terminal::new().unwrap();
|
||||
|
||||
loop {
|
||||
// Render and display a frame. A full frame is displayed on the terminal
|
||||
// once this function exits.
|
||||
render_frame(&mut term);
|
||||
|
||||
// Exit if the user presses any buttons
|
||||
if !matches!(crossterm::event::read().unwrap(), Event::Resize(_, _)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for input before exiting
|
||||
let _ = crossterm::event::read();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use std::io;
|
||||
|
||||
use crossterm::event::Event;
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use toss::frame::{Frame, Pos};
|
||||
use toss::terminal::Terminal;
|
||||
use toss::terminal::{Redraw, Terminal};
|
||||
|
||||
fn draw(f: &mut Frame) {
|
||||
f.write(
|
||||
|
|
@ -58,24 +57,32 @@ fn draw(f: &mut Frame) {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
// Automatically enters alternate screen and enables raw mode
|
||||
let mut term = Terminal::new()?;
|
||||
|
||||
fn render_frame(term: &mut Terminal) {
|
||||
loop {
|
||||
// Must be called before rendering, otherwise the terminal has out-of-date
|
||||
// size information and will present garbage.
|
||||
term.autoresize()?;
|
||||
term.autoresize().unwrap();
|
||||
|
||||
draw(term.frame());
|
||||
|
||||
if !term.present()? {
|
||||
if term.present().unwrap() == Redraw::NotRequired {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Automatically enters alternate screen and enables raw mode
|
||||
let mut term = Terminal::new().unwrap();
|
||||
|
||||
loop {
|
||||
// Render and display a frame. A full frame is displayed on the terminal
|
||||
// once this function exits.
|
||||
render_frame(&mut term);
|
||||
|
||||
// Exit if the user presses any buttons
|
||||
if !matches!(crossterm::event::read().unwrap(), Event::Resize(_, _)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for input before exiting
|
||||
let _ = crossterm::event::read();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue