diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-10-14 12:50:38 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2020-10-14 14:58:02 +0300 |
commit | 188e020bd1fdb4320ac44a6190b27d5ca7e44bae (patch) | |
tree | 0de55405aafdedc33b63ee98d9a1131bde34e7ae /src/state.rs | |
parent | 20840625d65db062a9f4a324f1265a24753cda83 (diff) |
Add opt-in mouse support
Sidebar width can be resized with mouse hold and drag.
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/state.rs b/src/state.rs index 2d0fbee8..88536b15 100644 --- a/src/state.rs +++ b/src/state.rs @@ -178,6 +178,7 @@ pub struct State { overlay_grid: CellBuffer, draw_rate_limit: RateLimit, stdout: Option<StateStdout>, + mouse: bool, child: Option<ForkType>, draw_horizontal_segment_fn: fn(&mut CellBuffer, &mut StateStdout, usize, usize, usize) -> (), pub mode: UIMode, @@ -318,6 +319,7 @@ impl State { grid: CellBuffer::new(cols, rows, Cell::with_char(' ')), overlay_grid: CellBuffer::new(cols, rows, Cell::with_char(' ')), stdout: None, + mouse: settings.terminal.use_mouse.is_true(), child: None, mode: UIMode::Normal, components: Vec::with_capacity(8), @@ -419,13 +421,16 @@ impl State { /// Switch back to the terminal's main screen (The command line the user sees before opening /// the application) pub fn switch_to_main_screen(&mut self) { + let mouse = self.mouse; write!( self.stdout(), - "{}{}{}{}", + "{}{}{}{}{disable_sgr_mouse}{disable_mouse}", termion::screen::ToMainScreen, cursor::Show, RestoreWindowTitleIconFromStack, BracketModeEnd, + disable_sgr_mouse = if mouse { DisableSGRMouse.as_ref() } else { "" }, + disable_mouse = if mouse { DisableMouse.as_ref() } else { "" }, ) .unwrap(); self.flush(); @@ -439,7 +444,7 @@ impl State { write!( &mut stdout, - "{save_title_to_stack}{}{}{}{window_title}{}{}", + "{save_title_to_stack}{}{}{}{window_title}{}{}{enable_mouse}{enable_sgr_mouse}", termion::screen::ToAlternateScreen, cursor::Hide, clear::All, @@ -451,6 +456,12 @@ impl State { } else { String::new() }, + enable_mouse = if self.mouse { EnableMouse.as_ref() } else { "" }, + enable_sgr_mouse = if self.mouse { + EnableSGRMouse.as_ref() + } else { + "" + }, ) .unwrap(); @@ -458,6 +469,27 @@ impl State { self.flush(); } + pub fn set_mouse(&mut self, value: bool) { + if let Some(stdout) = self.stdout.as_mut() { + write!( + stdout, + "{mouse}{sgr_mouse}", + mouse = if value { + AsRef::<str>::as_ref(&EnableMouse) + } else { + AsRef::<str>::as_ref(&DisableMouse) + }, + sgr_mouse = if value { + AsRef::<str>::as_ref(&EnableSGRMouse) + } else { + AsRef::<str>::as_ref(&DisableSGRMouse) + }, + ) + .unwrap(); + } + self.flush(); + } + pub fn receiver(&self) -> Receiver<ThreadEvent> { self.context.receiver.clone() } @@ -945,6 +977,11 @@ impl State { .unwrap_or_else(|err| err.to_string()) )))); } + ToggleMouse => { + self.mouse = !self.mouse; + self.set_mouse(self.mouse); + self.rcv_event(UIEvent::StatusEvent(StatusEvent::SetMouse(self.mouse))); + } v => { self.rcv_event(UIEvent::Action(v)); } |