mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-22 07:11:01 +00:00
feat: implement automatic focus-based mouse toggling for logs view
This commit is contained in:
parent
fd6e2f9be3
commit
fef700ed41
4 changed files with 19 additions and 92 deletions
|
|
@ -46,6 +46,23 @@ func (gui *Gui) switchFocusAux(newView *gocui.View) error {
|
|||
|
||||
gui.g.Cursor = newView.Editable
|
||||
|
||||
// Automatically control mouse capture mode depending on focus
|
||||
if newView.Name() == "main" {
|
||||
if gui.g.Mouse {
|
||||
gui.g.Mouse = false
|
||||
gocui.Screen.DisableMouse()
|
||||
}
|
||||
} else {
|
||||
if !gui.Config.UserConfig.Gui.IgnoreMouseEvents {
|
||||
if !gui.g.Mouse {
|
||||
gui.g.Mouse = true
|
||||
gocui.Screen.EnableMouse()
|
||||
}
|
||||
}
|
||||
}
|
||||
// Force refresh the bottom information panel with updated status text
|
||||
_ = gui.renderString(gui.g, "information", gui.getInformationContent())
|
||||
|
||||
if err := gui.renderPanelOptions(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,13 +74,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||
Modifier: gocui.ModNone,
|
||||
Handler: gui.quit,
|
||||
},
|
||||
{
|
||||
ViewName: "",
|
||||
Key: 'M', // Shift+M
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: wrappedHandler(gui.handleToggleMouse),
|
||||
Description: "Toggle mouse mode (ON/OFF)",
|
||||
},
|
||||
|
||||
{
|
||||
ViewName: "",
|
||||
Key: gocui.KeyPgup,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ package gui
|
|||
|
||||
import (
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
)
|
||||
|
|
@ -113,84 +111,3 @@ func (gui *Gui) handleMainClick() error {
|
|||
|
||||
return gui.switchFocus(gui.Views.Main)
|
||||
}
|
||||
|
||||
var (
|
||||
mouseTimerMutex sync.Mutex
|
||||
mouseTimer *time.Timer
|
||||
mouseTicker *time.Ticker
|
||||
mouseTicksLeft int
|
||||
)
|
||||
|
||||
func (gui *Gui) handleToggleMouse() error {
|
||||
mouseTimerMutex.Lock()
|
||||
defer mouseTimerMutex.Unlock()
|
||||
|
||||
if gui.g.Mouse {
|
||||
// Disable Mouse
|
||||
gui.g.Mouse = false
|
||||
gocui.Screen.DisableMouse()
|
||||
|
||||
if mouseTimer != nil {
|
||||
mouseTimer.Stop()
|
||||
}
|
||||
if mouseTicker != nil {
|
||||
mouseTicker.Stop()
|
||||
}
|
||||
|
||||
mouseTicksLeft = 15
|
||||
mouseTimer = time.AfterFunc(15*time.Second, func() {
|
||||
gui.g.Update(func(g *gocui.Gui) error {
|
||||
mouseTimerMutex.Lock()
|
||||
defer mouseTimerMutex.Unlock()
|
||||
|
||||
if !gui.g.Mouse {
|
||||
gui.g.Mouse = true
|
||||
gocui.Screen.EnableMouse()
|
||||
if mouseTicker != nil {
|
||||
mouseTicker.Stop()
|
||||
}
|
||||
_ = gui.renderString(gui.g, "information", gui.getInformationContent())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
mouseTicker = time.NewTicker(1 * time.Second)
|
||||
go func() {
|
||||
for range mouseTicker.C {
|
||||
gui.g.Update(func(g *gocui.Gui) error {
|
||||
mouseTimerMutex.Lock()
|
||||
defer mouseTimerMutex.Unlock()
|
||||
|
||||
if gui.g.Mouse {
|
||||
return nil
|
||||
}
|
||||
mouseTicksLeft--
|
||||
if mouseTicksLeft <= 0 {
|
||||
if mouseTicker != nil {
|
||||
mouseTicker.Stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
_ = gui.renderString(gui.g, "information", gui.getInformationContent())
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
} else {
|
||||
// Enable Mouse manually
|
||||
gui.g.Mouse = true
|
||||
gocui.Screen.EnableMouse()
|
||||
|
||||
if mouseTimer != nil {
|
||||
mouseTimer.Stop()
|
||||
}
|
||||
if mouseTicker != nil {
|
||||
mouseTicker.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
_ = gui.renderString(gui.g, "information", gui.getInformationContent())
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
|
|
@ -199,7 +198,7 @@ func (gui *Gui) getInformationContent() string {
|
|||
|
||||
mouseStatus := "Mouse: ON"
|
||||
if !gui.g.Mouse {
|
||||
mouseStatus = fmt.Sprintf("Mouse: OFF (%ds left)", mouseTicksLeft)
|
||||
mouseStatus = "Mouse: OFF (Drag to copy)"
|
||||
}
|
||||
informationStr = mouseStatus + " | " + informationStr
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue