Vendor dependencies
Let's see how I like this workflow.
This commit is contained in:
parent
34d1830413
commit
9c435dc440
7500 changed files with 1665121 additions and 99 deletions
45
vendor/crossterm/examples/event-read-char-line.rs
vendored
Normal file
45
vendor/crossterm/examples/event-read-char-line.rs
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//! Demonstrates how to block read characters or a full line.
|
||||
//! Just note that crossterm is not required to do this and can be done with `io::stdin()`.
|
||||
//!
|
||||
//! cargo run --example event-read-char-line
|
||||
|
||||
use crossterm::{
|
||||
event::{self, Event, KeyCode, KeyEvent},
|
||||
Result,
|
||||
};
|
||||
|
||||
pub fn read_char() -> Result<char> {
|
||||
loop {
|
||||
if let Event::Key(KeyEvent {
|
||||
code: KeyCode::Char(c),
|
||||
..
|
||||
}) = event::read()?
|
||||
{
|
||||
return Ok(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_line() -> Result<String> {
|
||||
let mut line = String::new();
|
||||
while let Event::Key(KeyEvent { code, .. }) = event::read()? {
|
||||
match code {
|
||||
KeyCode::Enter => {
|
||||
break;
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
line.push(c);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(line)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("read line:");
|
||||
println!("{:?}", read_line());
|
||||
println!("read char:");
|
||||
println!("{:?}", read_char());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue