Crates.io | crossterm_input |
lib.rs | crossterm_input |
version | 0.5.0 |
source | src |
created_at | 2019-01-27 21:15:13.899133 |
updated_at | 2019-10-21 18:33:15.358921 |
description | A cross-platform library for reading userinput. |
homepage | |
repository | https://github.com/crossterm-rs/crossterm-input |
max_upload_size | |
id | 110998 |
size | 95,894 |
The crossterm_input
crate is deprecated and no longer maintained. The GitHub repository will
be archived soon. All the code is being moved to the crossterm
crate. You can learn more in the
Merge sub-crates to the crossterm crate
issue.
This crate allows you to read the user input cross-platform. It supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested see Tested Terminals for more info).
crossterm_input
is a sub-crate of the crossterm crate. You can use it
directly, but it's highly recommended to use the crossterm crate with
the input
feature enabled.
[dependencies]
# All crossterm features are enabled by default.
crossterm = "0.11"
use crossterm::{input, InputEvent, KeyEvent, MouseButton, MouseEvent, RawScreen, Result};
fn main() -> Result<()> {
// Keep _raw around, raw mode will be disabled on the _raw is dropped
let _raw = RawScreen::into_raw_mode()?;
let input = input();
input.enable_mouse_mode()?;
let mut sync_stdin = input.read_sync();
loop {
if let Some(event) = sync_stdin.next() {
match event {
InputEvent::Keyboard(KeyEvent::Esc) => break,
InputEvent::Keyboard(KeyEvent::Left) => println!("Left arrow"),
InputEvent::Mouse(MouseEvent::Press(MouseButton::Left, col, row)) => {
println!("Left mouse button pressed at {}x{}", col, row);
}
_ => println!("Other event {:?}", event),
}
}
}
input.disable_mouse_mode()
} // <- _raw dropped = raw mode disabled
This project is licensed under the MIT License - see the LICENSE file for details