1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

Bump gocui

This commit is contained in:
Stefan Haller
2023-08-02 11:34:01 +02:00
parent 4aca854b59
commit c5acbb6c7c
6 changed files with 44 additions and 25 deletions

View File

@ -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

View File

@ -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()

View File

@ -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}
}