Skip to content

Commit

Permalink
Check keyboard enhancement in the event-read example
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Nov 26, 2022
1 parent 50d172b commit 7f1c780
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions examples/event-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crossterm::{
read, DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
EnableFocusChange, EnableMouseCapture, Event, KeyCode,
},
execute,
execute, queue,
terminal::{disable_raw_mode, enable_raw_mode},
Result,
};
Expand Down Expand Up @@ -69,22 +69,38 @@ fn main() -> Result<()> {
enable_raw_mode()?;

let mut stdout = stdout();

let supports_keyboard_enhancement = matches!(
crossterm::terminal::supports_keyboard_enhancement(),
Ok(true)
);

if supports_keyboard_enhancement {
queue!(
stdout,
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_EVENT_TYPES
)
)?;
}

execute!(
stdout,
EnableBracketedPaste,
EnableFocusChange,
EnableMouseCapture,
PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES
| KeyboardEnhancementFlags::REPORT_EVENT_TYPES
)
)?;

if let Err(e) = print_events() {
println!("Error: {:?}\r", e);
}

if supports_keyboard_enhancement {
queue!(stdout, PopKeyboardEnhancementFlags)?;
}

execute!(
stdout,
DisableBracketedPaste,
Expand Down

0 comments on commit 7f1c780

Please sign in to comment.