Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Fix scroll in terminals on Windows #156

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}