Bump gocui

This commit is contained in:
Stefan Haller 2025-02-10 13:40:22 +01:00
parent 3012306ac3
commit 46ebfbbe87
5 changed files with 37 additions and 4 deletions

2
go.mod
View file

@ -16,7 +16,7 @@ require (
github.com/integrii/flaggy v1.4.0 github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
github.com/jesseduffield/gocui v0.3.1-0.20250207131741-38a8ffbf24fe github.com/jesseduffield/gocui v0.3.1-0.20250210123912-aba68ae65951
github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e

4
go.sum
View file

@ -188,8 +188,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/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 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/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
github.com/jesseduffield/gocui v0.3.1-0.20250207131741-38a8ffbf24fe h1:lNTwIp53mU5pfKYFinIsbUsd6mNxMit4IXcJUnn1Pc0= github.com/jesseduffield/gocui v0.3.1-0.20250210123912-aba68ae65951 h1:7/3M0yosAM9/aLAjTfzSJWhsWjT860ZVe4T76RPwE2k=
github.com/jesseduffield/gocui v0.3.1-0.20250207131741-38a8ffbf24fe/go.mod h1:sLIyZ2J42R6idGdtemZzsiR3xY5EF0KsvYEGh3dQv3s= github.com/jesseduffield/gocui v0.3.1-0.20250210123912-aba68ae65951/go.mod h1:sLIyZ2J42R6idGdtemZzsiR3xY5EF0KsvYEGh3dQv3s=
github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a h1:UDeJ3EBk04bXDLOPvuqM3on8HvyJfISw0+UMqW+0a4g= github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a h1:UDeJ3EBk04bXDLOPvuqM3on8HvyJfISw0+UMqW+0a4g=
github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a/go.mod h1:FSWDLKT0NQpntbDd1H3lbz51fhCVlMzy/J0S6nM727Q= github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a/go.mod h1:FSWDLKT0NQpntbDd1H3lbz51fhCVlMzy/J0S6nM727Q=
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY= github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=

View file

@ -157,6 +157,8 @@ type Gui struct {
// If Mouse is true then mouse events will be enabled. // If Mouse is true then mouse events will be enabled.
Mouse bool Mouse bool
IsPasting bool
// If InputEsc is true, when ESC sequence is in the buffer and it doesn't // If InputEsc is true, when ESC sequence is in the buffer and it doesn't
// match any known sequence, ESC means KeyEsc. // match any known sequence, ESC means KeyEsc.
InputEsc bool InputEsc bool
@ -759,6 +761,7 @@ func (g *Gui) MainLoop() error {
}() }()
Screen.EnableFocus() Screen.EnableFocus()
Screen.EnablePaste()
previousEnableMouse := false previousEnableMouse := false
for { for {
@ -847,6 +850,9 @@ func (g *Gui) handleEvent(ev *GocuiEvent) error {
return nil return nil
case eventFocus: case eventFocus:
return g.onFocus(ev) return g.onFocus(ev)
case eventPaste:
g.IsPasting = ev.Start
return nil
default: default:
return nil return nil
} }
@ -1305,6 +1311,20 @@ func (g *Gui) onKey(ev *GocuiEvent) error {
switch ev.Type { switch ev.Type {
case eventKey: case eventKey:
// When pasting text in Ghostty, it sends us '\r' instead of '\n' for
// newlines. I actually don't quite understand why, because from reading
// Ghostty's source code (e.g.
// https://github.com/ghostty-org/ghostty/commit/010338354a0) it does
// this conversion only for non-bracketed paste mode, but I'm seeing it
// in bracketed paste mode. Whatever I'm missing here, converting '\r'
// back to '\n' fixes pasting multi-line text from Ghostty, and doesn't
// seem harmful for other terminal emulators.
//
// KeyCtrlJ (int value 10) is '\r', and KeyCtrlM (int value 13) is '\n'.
if g.IsPasting && ev.Key == KeyCtrlJ {
ev.Key = KeyCtrlM
}
err := g.execKeybindings(g.currentView, ev) err := g.execKeybindings(g.currentView, ev)
if err != nil { if err != nil {
return err return err
@ -1469,6 +1489,10 @@ func (g *Gui) execKeybindings(v *View, ev *GocuiEvent) error {
var globalKb *keybinding var globalKb *keybinding
var matchingParentViewKb *keybinding var matchingParentViewKb *keybinding
if g.IsPasting && v != nil && !v.Editable {
return nil
}
// if we're searching, and we've hit n/N/Esc, we ignore the default keybinding // if we're searching, and we've hit n/N/Esc, we ignore the default keybinding
if v != nil && v.IsSearching() && ev.Mod == ModNone { if v != nil && v.IsSearching() && ev.Mod == ModNone {
if eventMatchesKey(ev, g.NextSearchMatchKey) { if eventMatchesKey(ev, g.NextSearchMatchKey) {

View file

@ -155,6 +155,8 @@ type gocuiEventType uint8
// The 'MouseX' and 'MouseY' fields are valid if 'Type' is 'eventMouse'. // The 'MouseX' and 'MouseY' fields are valid if 'Type' is 'eventMouse'.
// The 'Width' and 'Height' fields are valid if 'Type' is 'eventResize'. // The 'Width' and 'Height' fields are valid if 'Type' is 'eventResize'.
// The 'Focused' field is valid if 'Type' is 'eventFocus'. // The 'Focused' field is valid if 'Type' is 'eventFocus'.
// The 'Start' field is valid if 'Type' is 'eventPaste'. It is true for the
// beginning of a paste operation, false for the end.
// The 'Err' field is valid if 'Type' is 'eventError'. // The 'Err' field is valid if 'Type' is 'eventError'.
type GocuiEvent struct { type GocuiEvent struct {
Type gocuiEventType Type gocuiEventType
@ -167,6 +169,7 @@ type GocuiEvent struct {
MouseX int MouseX int
MouseY int MouseY int
Focused bool Focused bool
Start bool
N int N int
} }
@ -178,6 +181,7 @@ const (
eventMouse eventMouse
eventMouseMove // only used when no button is down, otherwise it's eventMouse eventMouseMove // only used when no button is down, otherwise it's eventMouse
eventFocus eventFocus
eventPaste
eventInterrupt eventInterrupt
eventError eventError
eventRaw eventRaw
@ -417,6 +421,11 @@ func (g *Gui) pollEvent() GocuiEvent {
Type: eventFocus, Type: eventFocus,
Focused: tev.Focused, Focused: tev.Focused,
} }
case *tcell.EventPaste:
return GocuiEvent{
Type: eventPaste,
Start: tev.Start(),
}
default: default:
return GocuiEvent{Type: eventNone} return GocuiEvent{Type: eventNone}
} }

2
vendor/modules.txt vendored
View file

@ -171,7 +171,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/index
github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
# github.com/jesseduffield/gocui v0.3.1-0.20250207131741-38a8ffbf24fe # github.com/jesseduffield/gocui v0.3.1-0.20250210123912-aba68ae65951
## explicit; go 1.12 ## explicit; go 1.12
github.com/jesseduffield/gocui github.com/jesseduffield/gocui
# github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a # github.com/jesseduffield/kill v0.0.0-20250101124109-e216ddbe133a