forked from mars/breed
Better raw mode and screen handling
This commit is contained in:
parent
b03a5b47ea
commit
2b62862559
25
src/main.rs
25
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::io::{stdin, stdout, Read, Write};
|
use std::io::{stdin, stdout, Read, Stdout, Write};
|
||||||
|
|
||||||
use crossterm::{cursor, event, terminal, ExecutableCommand, Result};
|
use crossterm::{cursor, event, terminal, ExecutableCommand, Result};
|
||||||
use event::{Event, KeyCode, KeyEvent};
|
use event::{Event, KeyCode, KeyEvent};
|
||||||
|
@ -248,19 +248,24 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn screen_main(stdout: &mut Stdout, mut state: State) -> Result<()> {
|
||||||
let text = include_str!("main.rs");
|
|
||||||
let mut state = State::from_str(text);
|
|
||||||
let mut stdout = stdout();
|
|
||||||
terminal::enable_raw_mode()?;
|
|
||||||
stdout.execute(terminal::EnterAlternateScreen)?;
|
|
||||||
|
|
||||||
while !state.quit {
|
while !state.quit {
|
||||||
state.draw(&mut stdout)?;
|
state.draw(stdout)?;
|
||||||
let event = event::read()?;
|
let event = event::read()?;
|
||||||
state.on_event(event);
|
state.on_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.execute(terminal::LeaveAlternateScreen)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let text = include_str!("main.rs");
|
||||||
|
let state = State::from_str(text);
|
||||||
|
let mut stdout = stdout();
|
||||||
|
terminal::enable_raw_mode()?;
|
||||||
|
stdout.execute(terminal::EnterAlternateScreen)?;
|
||||||
|
let result = screen_main(&mut stdout, state);
|
||||||
|
stdout.execute(terminal::LeaveAlternateScreen)?;
|
||||||
|
terminal::disable_raw_mode()?;
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue