2021-04-11 13:52:04 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
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"
|
2023-08-05 18:56:21 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
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 {
|
2023-03-23 09:47:29 +02:00
|
|
|
if activeMode, ok := gui.helpers.Mode.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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleInfoClick() error {
|
|
|
|
if !gui.g.Mouse {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
view := gui.Views.Information
|
|
|
|
|
|
|
|
cx, _ := view.Cursor()
|
|
|
|
width, _ := view.Size()
|
|
|
|
|
2023-03-23 09:47:29 +02:00
|
|
|
if activeMode, ok := gui.helpers.Mode.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
|
|
|
}
|
2023-03-23 09:47:29 +02:00
|
|
|
return activeMode.Reset()
|
2021-04-11 13:52:04 +02:00
|
|
|
}
|
|
|
|
|
2023-08-05 18:56:21 +02:00
|
|
|
var title, url string
|
|
|
|
|
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) {
|
2023-08-05 18:56:21 +02:00
|
|
|
url = constants.Links.Donate
|
|
|
|
title = gui.c.Tr.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) {
|
2023-08-05 18:56:21 +02:00
|
|
|
url = constants.Links.Discussions
|
|
|
|
title = gui.c.Tr.AskQuestion
|
|
|
|
}
|
|
|
|
err := gui.os.OpenLink(url)
|
|
|
|
if err != nil {
|
|
|
|
// Opening the link via the OS failed for some reason. (For example, this
|
|
|
|
// can happen if the `os.openLink` config key references a command that
|
|
|
|
// doesn't exist, or that errors when called.)
|
|
|
|
//
|
|
|
|
// In that case, rather than crash the app, fall back to simply showing a
|
|
|
|
// dialog asking the user to visit the URL.
|
|
|
|
placeholders := map[string]string{"url": url}
|
|
|
|
message := utils.ResolvePlaceholderString(gui.c.Tr.PleaseGoToURL, placeholders)
|
|
|
|
return gui.c.Alert(title, message)
|
2021-04-11 13:52:04 +02:00
|
|
|
}
|
2023-08-05 18:56:21 +02:00
|
|
|
|
2021-04-11 13:52:04 +02:00
|
|
|
return nil
|
|
|
|
}
|