Skip to content

Commit

Permalink
fix(search): only push and pop TUI keyboard enhancement flags on Unix…
Browse files Browse the repository at this point in the history
… platforms
  • Loading branch information
realfresh committed Sep 14, 2023
1 parent 0de63ed commit 974e33d
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/commands/search/framework/tui.rs
Expand Up @@ -35,13 +35,20 @@ impl<B: Backend> Tui<B> {
/// It enables the raw mode and sets terminal properties.
pub fn init(&mut self) -> Result<()> {
terminal::enable_raw_mode()?;
crossterm::execute!(
io::stderr(),
EnterAlternateScreen,
EnableMouseCapture,
// Keyboard event types are only reported on Windows by default, enable them on Unix too
PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)
)?;

if cfg!(target_family = "unix") {
// Keyboard event types are only reported on Windows by default, enable on Unix too
crossterm::execute!(
io::stderr(),
EnterAlternateScreen,
EnableMouseCapture,
PushKeyboardEnhancementFlags(KeyboardEnhancementFlags::REPORT_EVENT_TYPES)
)?;
} else {
// Don't add the keyboard enhancement flags on Windows, as it produces error:
// - Keyboard progressive enhancement not implemented for the legacy Windows API.
crossterm::execute!(io::stderr(), EnterAlternateScreen, EnableMouseCapture)?;
}

// Define a custom panic hook to reset the terminal properties.
// This way, you won't have your terminal messed up if an unexpected error happens.
Expand Down Expand Up @@ -76,12 +83,16 @@ impl<B: Backend> Tui<B> {
/// the terminal properties if unexpected errors occur.
fn reset() -> Result<()> {
terminal::disable_raw_mode()?;
crossterm::execute!(
io::stdout(),
LeaveAlternateScreen,
DisableMouseCapture,
PopKeyboardEnhancementFlags
)?;
if cfg!(target_family = "unix") {
crossterm::execute!(
io::stdout(),
LeaveAlternateScreen,
DisableMouseCapture,
PopKeyboardEnhancementFlags
)?;
} else {
crossterm::execute!(io::stdout(), LeaveAlternateScreen, DisableMouseCapture)?;
}
Ok(())
}

Expand Down

0 comments on commit 974e33d

Please sign in to comment.