Skip to content

Commit

Permalink
fix: 🐛 Fix scroll in terminals on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Adham-A committed Aug 22, 2023
1 parent 3f41ff9 commit ead2e05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ use {
termimad::crossterm::event::Event,
termimad::EventSource,
};
#[cfg(windows)]
use termimad::crossterm::event::{
MouseEventKind,
KeyCode,
KeyEvent,
KeyModifiers,
};

/// Run the mission and return the reference to the next
/// job to run, if any
Expand Down Expand Up @@ -77,6 +84,17 @@ pub fn run(
debug!("key pressed: {}", CroKey::from(key_event));
action = keybindings.get(key_event);
}
#[cfg(windows)]
Event::Mouse(mouse_event) => {
let key_code =
match mouse_event.kind {
MouseEventKind::ScrollDown => {KeyCode::Down}
MouseEventKind::ScrollUp => {KeyCode::Up}
_ => {KeyCode::Null}
};
action = keybindings.get(KeyEvent::new(key_code,KeyModifiers::NONE));
}
#[cfg(not(windows))]
_ => {}
}
event_source.unblock(false);
Expand Down
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ use {
termimad::EventSource,
};

#[cfg(windows)]
use termimad::crossterm::event::{
EnableMouseCapture,
DisableMouseCapture,
};
/// The Write type used by all GUI writing functions
pub type W = std::io::BufWriter<std::io::Stdout>;

Expand Down Expand Up @@ -106,6 +111,8 @@ pub fn run() -> anyhow::Result<()> {
let mut w = writer();
w.queue(EnterAlternateScreen)?;
w.queue(cursor::Hide)?;
#[cfg(windows)]
w.queue(EnableMouseCapture)?;

let event_source = EventSource::new()?;
let mut job_stack = JobStack::new(&settings);
Expand Down Expand Up @@ -141,6 +148,8 @@ pub fn run() -> anyhow::Result<()> {

w.queue(cursor::Show)?;
w.queue(LeaveAlternateScreen)?;
#[cfg(windows)]
w.queue(DisableMouseCapture)?;
w.flush()?;
result
}

0 comments on commit ead2e05

Please sign in to comment.