From 4aca854b5924b3228f9e69f7bc85dbb1287b4a3e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 26 Jul 2023 19:30:22 +0200 Subject: [PATCH 1/3] Point tcell at stefanhaller's fork This is temporary as long as https://github.com/gdamore/tcell/pull/599 is not merged. Once that PR is merged, we can revert this. --- go.mod | 2 + go.sum | 4 +- vendor/github.com/gdamore/tcell/v2/README.md | 1 + .../gdamore/tcell/v2/console_win.go | 4 + vendor/github.com/gdamore/tcell/v2/focus.go | 28 +++++++ vendor/github.com/gdamore/tcell/v2/screen.go | 6 ++ .../github.com/gdamore/tcell/v2/simulation.go | 6 ++ .../gdamore/tcell/v2/terminfo/terminfo.go | 2 + vendor/github.com/gdamore/tcell/v2/tscreen.go | 79 +++++++++++++++++++ vendor/modules.txt | 2 +- 10 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 vendor/github.com/gdamore/tcell/v2/focus.go diff --git a/go.mod b/go.mod index 13da2bd89..44f32432a 100644 --- a/go.mod +++ b/go.mod @@ -73,3 +73,5 @@ require ( golang.org/x/text v0.11.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) + +replace github.com/gdamore/tcell/v2 v2.6.0 => github.com/stefanhaller/tcell/v2 v2.6.1 diff --git a/go.sum b/go.sum index 559d12fb4..f4ef086fc 100644 --- a/go.sum +++ b/go.sum @@ -87,8 +87,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= -github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCySg= -github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5y65J2H8Y= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= @@ -274,6 +272,8 @@ github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad h1:fiWzISvDn0Csy5H0iwgAuJGQTUpVfEMJJd4nRFXogbc= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= +github.com/stefanhaller/tcell/v2 v2.6.1 h1:Qo4k5SOUc09q9xyA8juH4jFJy+neM9aQwJHgVO2/zBM= +github.com/stefanhaller/tcell/v2 v2.6.1/go.mod h1:PuJ7T6QKbsU7iVOHlhRoV3D/ipIAJsyiV4dbwcVaYj8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= diff --git a/vendor/github.com/gdamore/tcell/v2/README.md b/vendor/github.com/gdamore/tcell/v2/README.md index 347e274a2..8ca95eda9 100644 --- a/vendor/github.com/gdamore/tcell/v2/README.md +++ b/vendor/github.com/gdamore/tcell/v2/README.md @@ -65,6 +65,7 @@ A brief, and still somewhat rough, [tutorial](TUTORIAL.md) is available. - [todo](https://github.com/kyprifog/todo) - simple todo app - [gosnakego](https://github.com/liweiyi88/gosnakego) - a snake game - [gbb](https://github.com/sdemingo/gbb) - A classical bulletin board app for tildes or public unix servers +- [lil](https://github.com/andrievsky/lil) - A simple and flexible interface for any service by implementing only list and get operations ## Pure Go Terminfo Database diff --git a/vendor/github.com/gdamore/tcell/v2/console_win.go b/vendor/github.com/gdamore/tcell/v2/console_win.go index 5f0063e26..01fa1f7bf 100644 --- a/vendor/github.com/gdamore/tcell/v2/console_win.go +++ b/vendor/github.com/gdamore/tcell/v2/console_win.go @@ -282,6 +282,10 @@ func (s *cScreen) EnablePaste() {} func (s *cScreen) DisablePaste() {} +func (s *cScreen) EnableFocus() {} + +func (s *cScreen) DisableFocus() {} + func (s *cScreen) Fini() { s.disengage() } diff --git a/vendor/github.com/gdamore/tcell/v2/focus.go b/vendor/github.com/gdamore/tcell/v2/focus.go new file mode 100644 index 000000000..e9b93ef6d --- /dev/null +++ b/vendor/github.com/gdamore/tcell/v2/focus.go @@ -0,0 +1,28 @@ +// Copyright 2023 The TCell Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use file except in compliance with the License. +// You may obtain a copy of the license at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tcell + +// EventFocus is a focus event. It is sent when the terminal window (or tab) +// gets or loses focus. +type EventFocus struct { + *EventTime + + // True if the window received focus, false if it lost focus + Focused bool +} + +func NewEventFocus(focused bool) *EventFocus { + return &EventFocus{Focused: focused} +} diff --git a/vendor/github.com/gdamore/tcell/v2/screen.go b/vendor/github.com/gdamore/tcell/v2/screen.go index 5598a8c7a..bd35a89dd 100644 --- a/vendor/github.com/gdamore/tcell/v2/screen.go +++ b/vendor/github.com/gdamore/tcell/v2/screen.go @@ -139,6 +139,12 @@ type Screen interface { // DisablePaste disables bracketed paste mode. DisablePaste() + // EnableFocus enables reporting of focus events, if your terminal supports it. + EnableFocus() + + // DisableFocus disables reporting of focus events. + DisableFocus() + // HasMouse returns true if the terminal (apparently) supports a // mouse. Note that the return value of true doesn't guarantee that // a mouse/pointing device is present; a false return definitely diff --git a/vendor/github.com/gdamore/tcell/v2/simulation.go b/vendor/github.com/gdamore/tcell/v2/simulation.go index 9ad6131ec..b18b6648d 100644 --- a/vendor/github.com/gdamore/tcell/v2/simulation.go +++ b/vendor/github.com/gdamore/tcell/v2/simulation.go @@ -325,6 +325,12 @@ func (s *simscreen) DisablePaste() { s.paste = false } +func (s *simscreen) EnableFocus() { +} + +func (s *simscreen) DisableFocus() { +} + func (s *simscreen) Size() (int, int) { s.Lock() w, h := s.back.Size() diff --git a/vendor/github.com/gdamore/tcell/v2/terminfo/terminfo.go b/vendor/github.com/gdamore/tcell/v2/terminfo/terminfo.go index cf1578648..c248dd49c 100644 --- a/vendor/github.com/gdamore/tcell/v2/terminfo/terminfo.go +++ b/vendor/github.com/gdamore/tcell/v2/terminfo/terminfo.go @@ -230,6 +230,8 @@ type Terminfo struct { EnterUrl string ExitUrl string SetWindowSize string + EnableFocusReporting string + DisableFocusReporting string } const ( diff --git a/vendor/github.com/gdamore/tcell/v2/tscreen.go b/vendor/github.com/gdamore/tcell/v2/tscreen.go index e36e6e41f..27635d38a 100644 --- a/vendor/github.com/gdamore/tcell/v2/tscreen.go +++ b/vendor/github.com/gdamore/tcell/v2/tscreen.go @@ -153,6 +153,8 @@ type tScreen struct { enterUrl string exitUrl string setWinSize string + enableFocus string + disableFocus string cursorStyles map[CursorStyle]string cursorStyle CursorStyle saved *term.State @@ -161,6 +163,7 @@ type tScreen struct { wg sync.WaitGroup mouseFlags MouseFlags pasteEnabled bool + focusEnabled bool sync.Mutex } @@ -366,6 +369,17 @@ func (t *tScreen) prepareExtendedOSC() { } else if t.ti.Mouse != "" { t.setWinSize = "\x1b[8;%p1%p2%d;%dt" } + + if t.ti.EnableFocusReporting != "" { + t.enableFocus = t.ti.EnableFocusReporting + } else if t.ti.Mouse != "" { + t.enableFocus = "\x1b[?1004h" + } + if t.ti.DisableFocusReporting != "" { + t.disableFocus = t.ti.DisableFocusReporting + } else if t.ti.Mouse != "" { + t.disableFocus = "\x1b[?1004l" + } } func (t *tScreen) prepareCursorStyles() { @@ -1043,6 +1057,32 @@ func (t *tScreen) enablePasting(on bool) { } } +func (t *tScreen) EnableFocus() { + t.Lock() + t.focusEnabled = true + t.enableFocusReporting() + t.Unlock() +} + +func (t *tScreen) DisableFocus() { + t.Lock() + t.focusEnabled = false + t.disableFocusReporting() + t.Unlock() +} + +func (t *tScreen) enableFocusReporting() { + if t.enableFocus != "" { + t.TPuts(t.enableFocus) + } +} + +func (t *tScreen) disableFocusReporting() { + if t.disableFocus != "" { + t.TPuts(t.disableFocus) + } +} + func (t *tScreen) Size() (int, int) { t.Lock() w, h := t.w, t.h @@ -1380,6 +1420,35 @@ func (t *tScreen) parseSgrMouse(buf *bytes.Buffer, evs *[]Event) (bool, bool) { return true, false } +func (t *tScreen) parseFocus(buf *bytes.Buffer, evs *[]Event) (bool, bool) { + state := 0 + b := buf.Bytes() + for i := range b { + switch state { + case 0: + if b[i] != '\x1b' { + return false, false + } + state = 1 + case 1: + if b[i] != '[' { + return false, false + } + state = 2 + case 2: + if b[i] != 'I' && b[i] != 'O' { + return false, false + } + *evs = append(*evs, NewEventFocus(b[i] == 'I')) + _, _ = buf.ReadByte() + _, _ = buf.ReadByte() + _, _ = buf.ReadByte() + return true, true + } + } + return true, false +} + // parseXtermMouse is like parseSgrMouse, but it parses a legacy // X11 mouse record. func (t *tScreen) parseXtermMouse(buf *bytes.Buffer, evs *[]Event) (bool, bool) { @@ -1556,6 +1625,12 @@ func (t *tScreen) collectEventsFromInput(buf *bytes.Buffer, expire bool) []Event partials++ } + if part, comp := t.parseFocus(buf, &res); comp { + continue + } else if part { + partials++ + } + // Only parse mouse records if this term claims to have // mouse support @@ -1804,6 +1879,9 @@ func (t *tScreen) engage() error { t.stopQ = stopQ t.enableMouse(t.mouseFlags) t.enablePasting(t.pasteEnabled) + if t.focusEnabled { + t.enableFocusReporting() + } ti := t.ti t.TPuts(ti.EnterCA) @@ -1853,6 +1931,7 @@ func (t *tScreen) disengage() { t.TPuts(ti.ExitKeypad) t.enableMouse(0) t.enablePasting(false) + t.disableFocusReporting() _ = t.tty.Stop() } diff --git a/vendor/modules.txt b/vendor/modules.txt index d019f976a..c4937182b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -36,7 +36,7 @@ github.com/fsnotify/fsnotify # github.com/gdamore/encoding v1.0.0 ## explicit; go 1.9 github.com/gdamore/encoding -# github.com/gdamore/tcell/v2 v2.6.0 +# github.com/gdamore/tcell/v2 v2.6.0 => github.com/stefanhaller/tcell/v2 v2.6.1 ## explicit; go 1.12 github.com/gdamore/tcell/v2 github.com/gdamore/tcell/v2/terminfo From c5acbb6c7c9678c5ff55e490a18b3ce4f3d7df37 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 2 Aug 2023 11:34:01 +0200 Subject: [PATCH 2/3] Bump gocui --- go.mod | 4 +-- go.sum | 12 +++----- vendor/github.com/jesseduffield/gocui/edit.go | 4 +-- vendor/github.com/jesseduffield/gocui/gui.go | 17 +++++++++++ .../jesseduffield/gocui/tcell_driver.go | 28 ++++++++++++------- vendor/modules.txt | 4 +-- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 44f32432a..8cde82747 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/integrii/flaggy v1.4.0 github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d - github.com/jesseduffield/gocui v0.3.1-0.20230723014157-03e858e46144 + github.com/jesseduffield/gocui v0.3.1-0.20230802092815-ae0a5c181634 github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e @@ -25,7 +25,7 @@ require ( github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/kyokomi/emoji/v2 v2.2.8 github.com/lucasb-eyer/go-colorful v1.2.0 - github.com/mattn/go-runewidth v0.0.14 + github.com/mattn/go-runewidth v0.0.15 github.com/mgutz/str v1.2.0 github.com/pmezard/go-difflib v1.0.0 github.com/sahilm/fuzzy v0.1.0 diff --git a/go.sum b/go.sum index f4ef086fc..5c3b09f5f 100644 --- a/go.sum +++ b/go.sum @@ -86,7 +86,6 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.2/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs= @@ -181,8 +180,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk= github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE= github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o= -github.com/jesseduffield/gocui v0.3.1-0.20230723014157-03e858e46144 h1:gwy5JzP6+PhcPFG1obkUSLGcTkUY88sLKlCPOFjwtak= -github.com/jesseduffield/gocui v0.3.1-0.20230723014157-03e858e46144/go.mod h1:dJ/BEUt3OWtaRg/PmuJWendRqREhre9JQ1SLvqrVJ8s= +github.com/jesseduffield/gocui v0.3.1-0.20230802092815-ae0a5c181634 h1:tL9DS59Po4kw1fR+wFn0zUYQhrgxMskTatLcYQl7MMU= +github.com/jesseduffield/gocui v0.3.1-0.20230802092815-ae0a5c181634/go.mod h1:pArPLsN1+S6jDrBDukTkpnH89rdhw44wzKdXFICGH3Q= github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0= github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo= github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY= @@ -214,7 +213,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/kyokomi/emoji/v2 v2.2.8 h1:jcofPxjHWEkJtkIbcLHvZhxKgCPl6C7MyjTrD4KDqUE= github.com/kyokomi/emoji/v2 v2.2.8/go.mod h1:JUcn42DTdsXJo1SWanHh4HKDEyPaR5CqkmoirZZP9qE= -github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -226,9 +224,9 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mgutz/str v1.2.0 h1:4IzWSdIz9qPQWLfKZ0rJcV0jcUDpxvP4JVZ4GXQyvSw= github.com/mgutz/str v1.2.0/go.mod h1:w1v0ofgLaJdoD0HpQ3fycxKD1WtxpjSo151pK/31q6w= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -250,7 +248,6 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= @@ -458,7 +455,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= diff --git a/vendor/github.com/jesseduffield/gocui/edit.go b/vendor/github.com/jesseduffield/gocui/edit.go index 0ad5d60a2..4ced2ad0a 100644 --- a/vendor/github.com/jesseduffield/gocui/edit.go +++ b/vendor/github.com/jesseduffield/gocui/edit.go @@ -63,9 +63,7 @@ func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool { v.TextArea.BackSpaceWord() case key == KeyCtrlY: v.TextArea.Yank() - - // TODO: see if we need all three of these conditions: maybe the final one is sufficient - case ch != 0 && mod == 0 && unicode.IsPrint(ch): + case unicode.IsPrint(ch): v.TextArea.TypeRune(ch) default: return false diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index d07287685..7a42fb7c3 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -128,6 +128,7 @@ type Gui struct { currentView *View managers []Manager keybindings []*keybinding + focusHandler func(bool) error maxX, maxY int outputMode OutputMode stop chan struct{} @@ -603,6 +604,10 @@ func (g *Gui) WhitelistKeybinding(k Key) error { return ErrNotBlacklisted } +func (g *Gui) SetFocusHandler(handler func(bool) error) { + g.focusHandler = handler +} + // getKey takes an empty interface with a key and returns the corresponding // typed Key or rune. func getKey(key interface{}) (Key, rune, error) { @@ -728,6 +733,8 @@ func (g *Gui) MainLoop() error { Screen.EnableMouse() } + Screen.EnableFocus() + for { err := g.processEvent() if err != nil { @@ -794,6 +801,8 @@ func (g *Gui) handleEvent(ev *GocuiEvent) error { case eventResize: g.onResize() return nil + case eventFocus: + return g.onFocus(ev) default: return nil } @@ -1418,6 +1427,14 @@ func (g *Gui) execKeybinding(v *View, kb *keybinding) (bool, error) { return true, nil } +func (g *Gui) onFocus(ev *GocuiEvent) error { + if g.focusHandler != nil { + return g.focusHandler(ev.Focused) + } + + return nil +} + func (g *Gui) StartTicking(ctx context.Context) { go func() { g.Mutexes.tickingMutex.Lock() diff --git a/vendor/github.com/jesseduffield/gocui/tcell_driver.go b/vendor/github.com/jesseduffield/gocui/tcell_driver.go index 545996804..1899c60a5 100644 --- a/vendor/github.com/jesseduffield/gocui/tcell_driver.go +++ b/vendor/github.com/jesseduffield/gocui/tcell_driver.go @@ -154,18 +154,20 @@ type gocuiEventType uint8 // The 'Mod', 'Key' and 'Ch' fields are valid if 'Type' is 'eventKey'. // The 'MouseX' and 'MouseY' fields are valid if 'Type' is 'eventMouse'. // The 'Width' and 'Height' fields are valid if 'Type' is 'eventResize'. +// The 'Focused' field is valid if 'Type' is 'eventFocus'. // The 'Err' field is valid if 'Type' is 'eventError'. type GocuiEvent struct { - Type gocuiEventType - Mod Modifier - Key Key - Ch rune - Width int - Height int - Err error - MouseX int - MouseY int - N int + Type gocuiEventType + Mod Modifier + Key Key + Ch rune + Width int + Height int + Err error + MouseX int + MouseY int + Focused bool + N int } // Event types. @@ -174,6 +176,7 @@ const ( eventKey eventResize eventMouse + eventFocus eventInterrupt eventError eventRaw @@ -368,6 +371,11 @@ func (g *Gui) pollEvent() GocuiEvent { Ch: 0, Mod: mouseMod, } + case *tcell.EventFocus: + return GocuiEvent{ + Type: eventFocus, + Focused: tev.Focused, + } default: return GocuiEvent{Type: eventNone} } diff --git a/vendor/modules.txt b/vendor/modules.txt index c4937182b..a4b8d4bef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -168,7 +168,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/noder -# github.com/jesseduffield/gocui v0.3.1-0.20230723014157-03e858e46144 +# github.com/jesseduffield/gocui v0.3.1-0.20230802092815-ae0a5c181634 ## explicit; go 1.12 github.com/jesseduffield/gocui # github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 @@ -210,7 +210,7 @@ github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.14 ## explicit; go 1.12 github.com/mattn/go-isatty -# github.com/mattn/go-runewidth v0.0.14 +# github.com/mattn/go-runewidth v0.0.15 ## explicit; go 1.9 github.com/mattn/go-runewidth # github.com/mgutz/str v1.2.0 From 8ce60662f2452bcb85b47b76f5a9aef0382a1f45 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 14 May 2023 16:33:25 +0200 Subject: [PATCH 3/3] Refresh when the terminal window gets the focus --- pkg/gui/gui.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f1e20da41..ad3dc3e34 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -288,6 +288,15 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context return err } + gui.g.SetFocusHandler(func(Focused bool) error { + if Focused { + gui.c.Log.Info("Receiving focus - refreshing") + return gui.helpers.Refresh.Refresh(types.RefreshOptions{Mode: types.ASYNC}) + } + + return nil + }) + // if a context key has been given, push that instead, and set its index to 0 if contextKey != context.NO_CONTEXT { contextToPush = gui.c.ContextForKey(contextKey)