-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Placed all user input into its own function in its own file.
- Loading branch information
1 parent
ce4fb88
commit b0c927a
Showing
3 changed files
with
39 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::{clear, Rain, Result, UserSettings}; | ||
use crossterm::{event, style}; | ||
use std::io::{BufWriter, Stdout}; | ||
use std::time::Duration; | ||
pub fn user_input( | ||
stdout: &mut BufWriter<Stdout>, | ||
rain: &mut Rain, | ||
user_settings: &UserSettings, | ||
create_color: fn(style::Color, style::Color, u8) -> Vec<style::Color>, | ||
) -> Result<bool> { | ||
if event::poll(Duration::from_millis(50))? { | ||
match event::read()? { | ||
event::Event::Key(keyevent) => { | ||
if keyevent | ||
== event::KeyEvent::new(event::KeyCode::Char('c'), event::KeyModifiers::CONTROL) | ||
|| keyevent | ||
== event::KeyEvent::new(event::KeyCode::Esc, event::KeyModifiers::NONE) | ||
{ | ||
return Ok(false); | ||
} | ||
} | ||
event::Event::Resize(w, h) => { | ||
clear(stdout)?; | ||
*rain = Rain::new(create_color, w, h, &user_settings); | ||
} | ||
_ => {} | ||
} | ||
} | ||
Ok(true) | ||
} |