aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-02 12:33:54 -0400
committerJesse Luehrs <doy@tozt.net>2019-11-02 12:35:52 -0400
commite50e3c4fe311d03d90c7bfb43b7612317fe183c0 (patch)
tree9b47b60dbd0e4d5c793a2f23c334c17f41cd81a8 /src
parente688ce7f57f126c5fa183ec74cc09f37df0bae8b (diff)
downloadvt100-rust-e50e3c4fe311d03d90c7bfb43b7612317fe183c0.tar.gz
vt100-rust-e50e3c4fe311d03d90c7bfb43b7612317fe183c0.zip
improve mouse mode handling
Diffstat (limited to 'src')
-rw-r--r--src/screen.rs109
1 files changed, 90 insertions, 19 deletions
diff --git a/src/screen.rs b/src/screen.rs
index 54e27a2..7e6f07b 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -12,14 +12,41 @@ enum Output {
enum Mode {
KeypadApplication,
ApplicationCursor,
- MouseReportingPress,
HideCursor,
- MouseReportingPressRelease,
- MouseReportingButtonMotion,
- MouseReportingSgr,
BracketedPaste,
}
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+enum MouseProtocolMode {
+ None,
+ Press,
+ PressRelease,
+ // Highlight,
+ ButtonMotion,
+ AnyMotion,
+ // DecLocator,
+}
+
+impl Default for MouseProtocolMode {
+ fn default() -> Self {
+ Self::None
+ }
+}
+
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+enum MouseProtocolEncoding {
+ Default,
+ Utf8,
+ Sgr,
+ // Urxvt,
+}
+
+impl Default for MouseProtocolEncoding {
+ fn default() -> Self {
+ Self::Default
+ }
+}
+
struct State {
grid: crate::grid::Grid,
alternate_grid: Option<crate::grid::Grid>,
@@ -31,6 +58,8 @@ struct State {
outputs: enumset::EnumSet<Output>,
modes: enumset::EnumSet<Mode>,
+ mouse_protocol_mode: MouseProtocolMode,
+ mouse_protocol_encoding: MouseProtocolEncoding,
}
impl State {
@@ -47,6 +76,8 @@ impl State {
outputs: enumset::EnumSet::default(),
modes: enumset::EnumSet::default(),
+ mouse_protocol_mode: MouseProtocolMode::default(),
+ mouse_protocol_encoding: MouseProtocolEncoding::default(),
}
}
@@ -124,6 +155,26 @@ impl State {
fn mode(&self, mode: Mode) -> bool {
self.modes.contains(mode)
}
+
+ fn set_mouse_mode(&mut self, mode: MouseProtocolMode) {
+ self.mouse_protocol_mode = mode;
+ }
+
+ fn clear_mouse_mode(&mut self, mode: MouseProtocolMode) {
+ if self.mouse_protocol_mode == mode {
+ self.mouse_protocol_mode = MouseProtocolMode::default();
+ }
+ }
+
+ fn set_mouse_encoding(&mut self, encoding: MouseProtocolEncoding) {
+ self.mouse_protocol_encoding = encoding;
+ }
+
+ fn clear_mouse_encoding(&mut self, encoding: MouseProtocolEncoding) {
+ if self.mouse_protocol_encoding == encoding {
+ self.mouse_protocol_encoding = MouseProtocolEncoding::default();
+ }
+ }
}
impl State {
@@ -244,6 +295,8 @@ impl State {
self.alternate_grid = None;
self.attrs = crate::attrs::Attrs::default();
self.modes = enumset::EnumSet::default();
+ self.mouse_protocol_mode = MouseProtocolMode::default();
+ self.mouse_protocol_encoding = MouseProtocolEncoding::default();
}
// ESC g
@@ -374,11 +427,13 @@ impl State {
match param {
1 => self.set_mode(Mode::ApplicationCursor),
6 => self.grid_mut().set_origin_mode(true),
- 9 => self.set_mode(Mode::MouseReportingPress),
+ 9 => self.set_mouse_mode(MouseProtocolMode::Press),
25 => self.clear_mode(Mode::HideCursor),
- 1000 => self.set_mode(Mode::MouseReportingPressRelease),
- 1002 => self.set_mode(Mode::MouseReportingButtonMotion),
- 1006 => self.set_mode(Mode::MouseReportingSgr),
+ 1000 => self.set_mouse_mode(MouseProtocolMode::PressRelease),
+ 1002 => self.set_mouse_mode(MouseProtocolMode::ButtonMotion),
+ 1003 => self.set_mouse_mode(MouseProtocolMode::AnyMotion),
+ 1005 => self.set_mouse_encoding(MouseProtocolEncoding::Utf8),
+ 1006 => self.set_mouse_encoding(MouseProtocolEncoding::Sgr),
1049 => self.enter_alternate_grid(),
2004 => self.set_mode(Mode::BracketedPaste),
_ => {}
@@ -397,11 +452,19 @@ impl State {
match param {
1 => self.clear_mode(Mode::ApplicationCursor),
6 => self.grid_mut().set_origin_mode(false),
- 9 => self.clear_mode(Mode::MouseReportingPress),
+ 9 => self.clear_mouse_mode(MouseProtocolMode::Press),
25 => self.set_mode(Mode::HideCursor),
- 1000 => self.clear_mode(Mode::MouseReportingPressRelease),
- 1002 => self.clear_mode(Mode::MouseReportingButtonMotion),
- 1006 => self.clear_mode(Mode::MouseReportingSgr),
+ 1000 => {
+ self.clear_mouse_mode(MouseProtocolMode::PressRelease)
+ }
+ 1002 => {
+ self.clear_mouse_mode(MouseProtocolMode::ButtonMotion)
+ }
+ 1003 => self.clear_mouse_mode(MouseProtocolMode::AnyMotion),
+ 1005 => {
+ self.clear_mouse_encoding(MouseProtocolEncoding::Utf8)
+ }
+ 1006 => self.clear_mouse_encoding(MouseProtocolEncoding::Sgr),
1049 => self.exit_alternate_grid(),
2004 => self.clear_mode(Mode::BracketedPaste),
_ => {}
@@ -756,20 +819,28 @@ impl Screen {
self.state.mode(Mode::BracketedPaste)
}
+ pub fn mouse_reporting_press(&self) -> bool {
+ self.state.mouse_protocol_mode == MouseProtocolMode::Press
+ }
+
+ pub fn mouse_reporting_press_release(&self) -> bool {
+ self.state.mouse_protocol_mode == MouseProtocolMode::PressRelease
+ }
+
pub fn mouse_reporting_button_motion(&self) -> bool {
- self.state.mode(Mode::MouseReportingButtonMotion)
+ self.state.mouse_protocol_mode == MouseProtocolMode::ButtonMotion
}
- pub fn mouse_reporting_sgr_mode(&self) -> bool {
- self.state.mode(Mode::MouseReportingSgr)
+ pub fn mouse_reporting_any_motion(&self) -> bool {
+ self.state.mouse_protocol_mode == MouseProtocolMode::AnyMotion
}
- pub fn mouse_reporting_press(&self) -> bool {
- self.state.mode(Mode::MouseReportingPress)
+ pub fn mouse_reporting_utf8_mode(&self) -> bool {
+ self.state.mouse_protocol_encoding == MouseProtocolEncoding::Utf8
}
- pub fn mouse_reporting_press_release(&self) -> bool {
- self.state.mode(Mode::MouseReportingPressRelease)
+ pub fn mouse_reporting_sgr_mode(&self) -> bool {
+ self.state.mouse_protocol_encoding == MouseProtocolEncoding::Sgr
}
pub fn check_audible_bell(&mut self) -> bool {