aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/input.rs
diff options
context:
space:
mode:
authorKirill Chibisov <wchibisovkirill@gmail.com>2019-11-04 22:41:13 +0300
committerChristian Duerr <contact@christianduerr.com>2019-11-04 20:41:13 +0100
commit2c671afb69fb97f94df9967e7ffcf07d5e6a7be1 (patch)
tree0333c0ee8bc6b1a10914af8c55448ae04d82bf5c /alacritty/src/input.rs
parent93e87eb0f1858138113d4ecdfaa8bfac3c127a39 (diff)
downloadr-alacritty-2c671afb69fb97f94df9967e7ffcf07d5e6a7be1.tar.gz
r-alacritty-2c671afb69fb97f94df9967e7ffcf07d5e6a7be1.tar.bz2
r-alacritty-2c671afb69fb97f94df9967e7ffcf07d5e6a7be1.zip
Add UTF-8 mouse mode support
Fixes #1934.
Diffstat (limited to 'alacritty/src/input.rs')
-rw-r--r--alacritty/src/input.rs39
1 files changed, 28 insertions, 11 deletions
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs
index 422d6a3f..5a852662 100644
--- a/alacritty/src/input.rs
+++ b/alacritty/src/input.rs
@@ -368,19 +368,36 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
pub fn normal_mouse_report(&mut self, button: u8) {
let (line, column) = (self.ctx.mouse().line, self.ctx.mouse().column);
+ let utf8 = self.ctx.terminal().mode().contains(TermMode::UTF8_MOUSE);
- if line < Line(223) && column < Column(223) {
- let msg = vec![
- b'\x1b',
- b'[',
- b'M',
- 32 + button,
- 32 + 1 + column.0 as u8,
- 32 + 1 + line.0 as u8,
- ];
-
- self.ctx.write_to_pty(msg);
+ let max_point = if utf8 { 2015 } else { 223 };
+
+ if line >= Line(max_point) || column >= Column(max_point) {
+ return;
+ }
+
+ let mut msg = vec![b'\x1b', b'[', b'M', 32 + button];
+
+ let mouse_pos_encode = |pos: usize| -> Vec<u8> {
+ let pos = 32 + 1 + pos;
+ let first = 0xC0 + pos / 64;
+ let second = 0x80 + (pos & 63);
+ vec![first as u8, second as u8]
+ };
+
+ if utf8 && column >= Column(95) {
+ msg.append(&mut mouse_pos_encode(column.0));
+ } else {
+ msg.push(32 + 1 + column.0 as u8);
+ }
+
+ if utf8 && line >= Line(95) {
+ msg.append(&mut mouse_pos_encode(line.0));
+ } else {
+ msg.push(32 + 1 + line.0 as u8);
}
+
+ self.ctx.write_to_pty(msg);
}
pub fn sgr_mouse_report(&mut self, button: u8, state: ElementState) {