Skip to content

Commit

Permalink
Initial mouse support
Browse files Browse the repository at this point in the history
* enable mouse support (termion MouseTerminal)
* handle scroll up and down events
  • Loading branch information
tlinford committed May 3, 2021
1 parent 325fc56 commit 5f9a305
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/common/input/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::actions::Action;
use super::keybinds::Keybinds;
use crate::common::input::config::Config;
use crate::common::{input::config::Config, utils::logging::debug_log_to_file};
use crate::common::{AppInstruction, SenderWithContext, OPENCALLS};
use crate::errors::ContextType;
use crate::os_input_output::OsApi;
Expand All @@ -11,7 +11,10 @@ use crate::screen::ScreenInstruction;
use crate::wasm_vm::PluginInstruction;
use crate::CommandIsExecuting;

use termion::input::{TermRead, TermReadEventsAndRaw};
use termion::{
event::MouseEvent,
input::{MouseTerminal, TermRead, TermReadEventsAndRaw},
};
use zellij_tile::data::{Event, InputMode, Key, ModeInfo};

/// Handles the dispatching of [`Action`]s according to the current
Expand Down Expand Up @@ -59,6 +62,9 @@ impl InputHandler {
let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
err_ctx.add_call(ContextType::StdinHandler);
let alt_left_bracket = vec![27, 91];
// should add a way to disable this, and store it somewhere (os_input_output?)
// mouse support goes away if it's dropped
let stdout = MouseTerminal::from(self.os_input.get_stdout_writer());
loop {
if self.should_exit {
break;
Expand All @@ -71,6 +77,20 @@ impl InputHandler {
let key = cast_termion_key(key);
self.handle_key(&key, raw_bytes);
}
termion::event::Event::Mouse(me) => {
// only handle mouse wheel scrolling for now
if let MouseEvent::Press(button, _, _) = me {
match button {
termion::event::MouseButton::WheelUp => {
self.dispatch_action(Action::ScrollUp);
}
termion::event::MouseButton::WheelDown => {
self.dispatch_action(Action::ScrollDown);
}
_ => {}
}
}
}
termion::event::Event::Unsupported(unsupported_key) => {
// we have to do this because of a bug in termion
// this should be a key event and not an unsupported event
Expand All @@ -79,10 +99,6 @@ impl InputHandler {
self.handle_key(&key, raw_bytes);
}
}
termion::event::Event::Mouse(_) => {
// Mouse events aren't implemented yet,
// use a NoOp untill then.
}
},
Err(err) => panic!("Encountered read error: {:?}", err),
}
Expand Down

0 comments on commit 5f9a305

Please sign in to comment.