2021-04-11 13:52:04 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-03-20 01:19:14 +02:00
|
|
|
"github.com/jesseduffield/generics/slices"
|
2021-04-11 15:32:20 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/constants"
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2022-05-07 11:02:09 +02:00
|
|
|
"github.com/mattn/go-runewidth"
|
2021-04-11 13:52:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func (gui *Gui) informationStr() string {
|
2022-03-20 01:19:14 +02:00
|
|
|
if activeMode, ok := gui.getActiveMode(); ok {
|
|
|
|
return activeMode.description()
|
2021-04-11 13:52:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if gui.g.Mouse {
|
2022-01-16 05:46:53 +02:00
|
|
|
donate := style.FgMagenta.SetUnderline().Sprint(gui.c.Tr.Donate)
|
|
|
|
askQuestion := style.FgYellow.SetUnderline().Sprint(gui.c.Tr.AskQuestion)
|
2021-04-11 13:52:04 +02:00
|
|
|
return fmt.Sprintf("%s %s %s", donate, askQuestion, gui.Config.GetVersion())
|
|
|
|
} else {
|
|
|
|
return gui.Config.GetVersion()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-20 01:19:14 +02:00
|
|
|
func (gui *Gui) getActiveMode() (modeStatus, bool) {
|
|
|
|
return slices.Find(gui.modeStatuses(), func(mode modeStatus) bool {
|
|
|
|
return mode.isActive()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-18 01:41:40 +02:00
|
|
|
func (gui *Gui) isAnyModeActive() bool {
|
|
|
|
return slices.Some(gui.modeStatuses(), func(mode modeStatus) bool {
|
|
|
|
return mode.isActive()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-11 13:52:04 +02:00
|
|
|
func (gui *Gui) handleInfoClick() error {
|
|
|
|
if !gui.g.Mouse {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
view := gui.Views.Information
|
|
|
|
|
|
|
|
cx, _ := view.Cursor()
|
|
|
|
width, _ := view.Size()
|
|
|
|
|
2022-03-20 01:19:14 +02:00
|
|
|
if activeMode, ok := gui.getActiveMode(); ok {
|
2022-05-07 11:02:09 +02:00
|
|
|
if width-cx > runewidth.StringWidth(gui.c.Tr.ResetInParentheses) {
|
2022-03-20 01:19:14 +02:00
|
|
|
return nil
|
2021-04-11 13:52:04 +02:00
|
|
|
}
|
2022-03-20 01:19:14 +02:00
|
|
|
return activeMode.reset()
|
2021-04-11 13:52:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we're not in an active mode we show the donate button
|
2022-05-07 11:02:09 +02:00
|
|
|
if cx <= runewidth.StringWidth(gui.c.Tr.Donate) {
|
2022-02-06 04:42:17 +02:00
|
|
|
return gui.os.OpenLink(constants.Links.Donate)
|
2022-05-07 11:02:09 +02:00
|
|
|
} else if cx <= runewidth.StringWidth(gui.c.Tr.Donate)+1+runewidth.StringWidth(gui.c.Tr.AskQuestion) {
|
2022-02-06 04:42:17 +02:00
|
|
|
return gui.os.OpenLink(constants.Links.Discussions)
|
2021-04-11 13:52:04 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|