parent
4423db687a
commit
e967c0410a
@ -1,3 +1,6 @@
|
|||||||
|
# Changes crossterm_input 0.3.3
|
||||||
|
- Removed println from `SyncReader`
|
||||||
|
|
||||||
# Changes crossterm_input 0.3.2
|
# Changes crossterm_input 0.3.2
|
||||||
- Fixed some special key combination detections for UNIX systems
|
- Fixed some special key combination detections for UNIX systems
|
||||||
- Windows mouse input event position was 0-based and should be 1-based
|
- Windows mouse input event position was 0-based and should be 1-based
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "crossterm_input"
|
name = "crossterm_input"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
authors = ["T. Post"]
|
authors = ["T. Post"]
|
||||||
description = "A cross-platform library for reading userinput."
|
description = "A cross-platform library for reading userinput."
|
||||||
repository = "https://github.com/TimonPost/crossterm"
|
repository = "https://github.com/TimonPost/crossterm"
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
extern crate crossterm_input;
|
extern crate crossterm_input;
|
||||||
extern crate crossterm_screen;
|
extern crate crossterm_screen;
|
||||||
|
|
||||||
use crossterm_input::{InputEvent, KeyEvent, MouseButton, MouseEvent, TerminalInput};
|
use crossterm_input::{input, InputEvent, KeyEvent, MouseButton, MouseEvent, RawScreen};
|
||||||
use crossterm_screen::Screen;
|
|
||||||
use std::{thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
fn process_input_event(key_event: InputEvent) -> bool {
|
fn process_input_event(key_event: InputEvent) -> bool {
|
||||||
@ -79,56 +78,56 @@ fn process_input_event(key_event: InputEvent) -> bool {
|
|||||||
|
|
||||||
pub fn read_asynchronously() {
|
pub fn read_asynchronously() {
|
||||||
// make sure to enable raw mode, this will make sure key events won't be handled by the terminal it's self and allows crossterm to read the input and pass it back to you.
|
// make sure to enable raw mode, this will make sure key events won't be handled by the terminal it's self and allows crossterm to read the input and pass it back to you.
|
||||||
let _ = Screen::new(true);
|
if let Ok(_raw) = RawScreen::into_raw_mode() {
|
||||||
|
let input = input();
|
||||||
|
|
||||||
let input = input();
|
// enable mouse events to be captured.
|
||||||
|
input.enable_mouse_mode().unwrap();
|
||||||
|
|
||||||
// enable mouse events to be captured.
|
let mut stdin = input.read_async();
|
||||||
input.enable_mouse_mode().unwrap();
|
|
||||||
|
|
||||||
let mut stdin = input.read_async();
|
loop {
|
||||||
|
if let Some(key_event) = stdin.next() {
|
||||||
loop {
|
if process_input_event(key_event) {
|
||||||
if let Some(key_event) = stdin.next() {
|
break;
|
||||||
if process_input_event(key_event) {
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
thread::sleep(Duration::from_millis(50));
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_millis(50));
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable mouse events to be captured.
|
// disable mouse events to be captured.
|
||||||
input.disable_mouse_mode().unwrap();
|
input.disable_mouse_mode().unwrap();
|
||||||
|
} // <=== raw modes will be disabled here
|
||||||
} // <=== background reader will be disposed when dropped.
|
} // <=== background reader will be disposed when dropped.
|
||||||
|
|
||||||
pub fn read_synchronously() {
|
pub fn read_synchronously() {
|
||||||
// make sure to enable raw mode, this will make sure key events won't be handled by the terminal it's self and allows crossterm to read the input and pass it back to you.
|
// make sure to enable raw mode, this will make sure key events won't be handled by the terminal it's self and allows crossterm to read the input and pass it back to you.
|
||||||
let _ = Screen::new(true);
|
if let Ok(_raw) = RawScreen::into_raw_mode() {
|
||||||
|
let input = input();
|
||||||
|
|
||||||
let input = input();
|
// enable mouse events to be captured.
|
||||||
|
input.enable_mouse_mode().unwrap();
|
||||||
|
|
||||||
// enable mouse events to be captured.
|
let mut sync_stdin = input.read_sync();
|
||||||
input.enable_mouse_mode().unwrap();
|
|
||||||
|
|
||||||
let mut sync_stdin = input.read_sync();
|
loop {
|
||||||
|
let event = sync_stdin.next();
|
||||||
|
|
||||||
loop {
|
if let Some(key_event) = event {
|
||||||
let event = sync_stdin.next();
|
if process_input_event(key_event) {
|
||||||
|
break;
|
||||||
if let Some(key_event) = event {
|
}
|
||||||
if process_input_event(key_event) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// disable mouse events to be captured.
|
// disable mouse events to be captured.
|
||||||
input.disable_mouse_mode().unwrap();
|
input.disable_mouse_mode().unwrap();
|
||||||
|
} // <=== raw modes will be disabled here
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// un-comment below and run with
|
// un-comment below and run with
|
||||||
// `cargo run --example key_events`:
|
// `cargo run --example key_events`:
|
||||||
// read_synchronously();
|
read_synchronously();
|
||||||
// read_asynchronously();
|
// read_asynchronously();
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,6 @@ impl Iterator for SyncReader {
|
|||||||
Ok(1) => match buf[0] {
|
Ok(1) => match buf[0] {
|
||||||
b'\x1B' => return Some(InputEvent::Keyboard(KeyEvent::Esc)),
|
b'\x1B' => return Some(InputEvent::Keyboard(KeyEvent::Esc)),
|
||||||
c => {
|
c => {
|
||||||
println!("size 1: {:?}", buf);
|
|
||||||
if let Ok(e) = parse_event(c, &mut source.bytes().flatten()) {
|
if let Ok(e) = parse_event(c, &mut source.bytes().flatten()) {
|
||||||
return Some(e);
|
return Some(e);
|
||||||
} else {
|
} else {
|
||||||
@ -128,7 +127,6 @@ impl Iterator for SyncReader {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(2) => {
|
Ok(2) => {
|
||||||
println!("size 2: {:?}", buf);
|
|
||||||
let option_iter = &mut Some(buf[1]).into_iter();
|
let option_iter = &mut Some(buf[1]).into_iter();
|
||||||
let mut iter = option_iter.map(|c| Ok(c)).chain(source.bytes());
|
let mut iter = option_iter.map(|c| Ok(c)).chain(source.bytes());
|
||||||
if let Ok(e) = parse_event(buf[0], &mut iter.flatten()) {
|
if let Ok(e) = parse_event(buf[0], &mut iter.flatten()) {
|
||||||
|
@ -184,8 +184,6 @@ fn into_virtual_terminal_sequence() -> Result<(u32, Vec<u8>)> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_key_event(key_event: &KeyEventRecord, seq: &mut Vec<u8>) {
|
fn handle_key_event(key_event: &KeyEventRecord, seq: &mut Vec<u8>) {
|
||||||
// println!("key code: {:?}, state: {:?}", key_event.virtual_key_code, key_event.control_key_state);
|
|
||||||
|
|
||||||
match key_event.virtual_key_code as i32 {
|
match key_event.virtual_key_code as i32 {
|
||||||
VK_SHIFT | VK_CONTROL | VK_MENU => {
|
VK_SHIFT | VK_CONTROL | VK_MENU => {
|
||||||
// ignore SHIFT, CTRL, ALT standalone presses
|
// ignore SHIFT, CTRL, ALT standalone presses
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
# Changes crossterm_input 0.9.3
|
||||||
|
- Removed println from `SyncReader`
|
||||||
|
|
||||||
## Changes crossterm 0.9.2
|
## Changes crossterm 0.9.2
|
||||||
- Terminal size linux was not 0-based
|
- Terminal size linux was not 0-based
|
||||||
- Windows mouse input event position was 0-based ans should be 1-based
|
- Windows mouse input event position was 0-based ans should be 1-based
|
||||||
|
Loading…
Reference in New Issue
Block a user