From 1f2980cbb4c956be045868a5140eb21641a0c240 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Sat, 31 Jul 2021 14:34:02 +0100 Subject: [PATCH] Persist mouse mode during buffer switching (#299) * Persist mouse mode during buffer switching * Update mouse.go --- internal/app/darktile/gui/mouse.go | 4 +-- internal/app/darktile/termutil/buffer.go | 10 ------ internal/app/darktile/termutil/csi.go | 36 +++++++++------------- internal/app/darktile/termutil/terminal.go | 10 ++++++ 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/internal/app/darktile/gui/mouse.go b/internal/app/darktile/gui/mouse.go index 8e3699bd..efa9d1c6 100644 --- a/internal/app/darktile/gui/mouse.go +++ b/internal/app/darktile/gui/mouse.go @@ -271,7 +271,7 @@ func (g *GUI) handleMouseRemotely(x, y int, pressedLeft, pressedMiddle, pressedR tx, ty := 1+(x/g.fontManager.CharSize().X), 1+(y/g.fontManager.CharSize().Y) - mode := g.terminal.GetActiveBuffer().GetMouseMode() + mode := g.terminal.GetMouseMode() switch mode { case termutil.MouseModeNone: @@ -295,7 +295,7 @@ func (g *GUI) handleMouseRemotely(x, y int, pressedLeft, pressedMiddle, pressedR var button rune - extMode := g.terminal.GetActiveBuffer().GetMouseExtMode() + extMode := g.terminal.GetMouseExtMode() switch true { case pressedLeft: diff --git a/internal/app/darktile/termutil/buffer.go b/internal/app/darktile/termutil/buffer.go index bedb814c..5b38bd53 100644 --- a/internal/app/darktile/termutil/buffer.go +++ b/internal/app/darktile/termutil/buffer.go @@ -25,8 +25,6 @@ type Buffer struct { charsets []*map[rune]rune // array of 2 charsets, nil means ASCII (no conversion) currentCharset int // active charset index in charsets array, valid values are 0 or 1 modes Modes - mouseMode MouseMode - mouseExtMode MouseExtMode selectionStart *Position selectionEnd *Position highlightStart *Position @@ -80,14 +78,6 @@ func (buffer *Buffer) IsCursorVisible() bool { return buffer.modes.ShowCursor } -func (buffer *Buffer) GetMouseMode() MouseMode { - return buffer.mouseMode -} - -func (buffer *Buffer) GetMouseExtMode() MouseExtMode { - return buffer.mouseExtMode -} - func (buffer *Buffer) IsApplicationCursorKeysModeEnabled() bool { return buffer.modes.ApplicationCursorKeys } diff --git a/internal/app/darktile/termutil/csi.go b/internal/app/darktile/termutil/csi.go index 855c89b9..757b67c6 100644 --- a/internal/app/darktile/termutil/csi.go +++ b/internal/app/darktile/termutil/csi.go @@ -717,11 +717,9 @@ func (t *Terminal) csiSetMode(modes string, enabled bool) bool { t.activeBuffer.modes.AutoWrap = enabled case "?9": if enabled { - //terminal.logger.Infof("Turning on X10 mouse mode") - t.activeBuffer.mouseMode = (MouseModeX10) + t.mouseMode = (MouseModeX10) } else { - //terminal.logger.Infof("Turning off X10 mouse mode") - t.activeBuffer.mouseMode = (MouseModeNone) + t.mouseMode = (MouseModeNone) } case "?12", "?13": t.activeBuffer.modes.BlinkingCursor = enabled @@ -737,46 +735,40 @@ func (t *Terminal) csiSetMode(modes string, enabled bool) bool { // enable mouse tracking // 1000 refers to ext mode for extended mouse click area - otherwise only x <= 255-31 if enabled { - t.activeBuffer.mouseMode = (MouseModeVT200) + t.mouseMode = (MouseModeVT200) } else { - t.activeBuffer.mouseMode = (MouseModeNone) + t.mouseMode = (MouseModeNone) } case "?1002": if enabled { - //terminal.logger.Infof("Turning on Button Event mouse mode") - t.activeBuffer.mouseMode = (MouseModeButtonEvent) + t.mouseMode = (MouseModeButtonEvent) } else { - //terminal.logger.Infof("Turning off Button Event mouse mode") - t.activeBuffer.mouseMode = (MouseModeNone) + t.mouseMode = (MouseModeNone) } case "?1003": if enabled { - t.activeBuffer.mouseMode = MouseModeAnyEvent + t.mouseMode = MouseModeAnyEvent } else { - t.activeBuffer.mouseMode = MouseModeNone + t.mouseMode = MouseModeNone } case "?1005": if enabled { - t.activeBuffer.mouseExtMode = MouseExtUTF + t.mouseExtMode = MouseExtUTF } else { - t.activeBuffer.mouseExtMode = MouseExtNone + t.mouseExtMode = MouseExtNone } case "?1006": if enabled { - //.logger.Infof("Turning on SGR ext mouse mode") - t.activeBuffer.mouseExtMode = MouseExtSGR + t.mouseExtMode = MouseExtSGR } else { - //terminal.logger.Infof("Turning off SGR ext mouse mode") - t.activeBuffer.mouseExtMode = (MouseExtNone) + t.mouseExtMode = (MouseExtNone) } case "?1015": if enabled { - //terminal.logger.Infof("Turning on URXVT ext mouse mode") - t.activeBuffer.mouseExtMode = (MouseExtURXVT) + t.mouseExtMode = (MouseExtURXVT) } else { - //terminal.logger.Infof("Turning off URXVT ext mouse mode") - t.activeBuffer.mouseExtMode = (MouseExtNone) + t.mouseExtMode = (MouseExtNone) } case "?1048": if enabled { diff --git a/internal/app/darktile/termutil/terminal.go b/internal/app/darktile/termutil/terminal.go index eacacfbe..b1eb669f 100644 --- a/internal/app/darktile/termutil/terminal.go +++ b/internal/app/darktile/termutil/terminal.go @@ -27,6 +27,8 @@ type Terminal struct { closeChan chan struct{} buffers []*Buffer activeBuffer *Buffer + mouseMode MouseMode + mouseExtMode MouseExtMode logFile *os.File theme *Theme running bool @@ -285,6 +287,14 @@ func (t *Terminal) switchBuffer(index uint8) { } } +func (t *Terminal) GetMouseMode() MouseMode { + return t.mouseMode +} + +func (t *Terminal) GetMouseExtMode() MouseExtMode { + return t.mouseExtMode +} + func (t *Terminal) GetActiveBuffer() *Buffer { return t.activeBuffer }