From fa79c927480b5e2ae3c9b17330053245a72d2ee0 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 19 Mar 2024 08:42:08 +0100 Subject: [PATCH 1/2] Make the links in the status panel point to the current version rather than master We've seen a lot of issues recently where people complain that lazygit doesn't behave as documented, but that was only because they were running the latest release but were looking at the documentation of master. Make the documentation links in the status panel point to the release that they are using in the hope that this will help a little bit with this problem. --- pkg/constants/links.go | 4 ++-- pkg/gui/controllers/status_controller.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/constants/links.go b/pkg/constants/links.go index c1335052b..e9b06cba3 100644 --- a/pkg/constants/links.go +++ b/pkg/constants/links.go @@ -28,9 +28,9 @@ var Links = struct { CustomPagers: "https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md", CustomKeybindings: "https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md", CustomCommands: "https://github.com/jesseduffield/lazygit/wiki/Custom-Commands-Compendium", - Keybindings: "https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings", + Keybindings: "https://github.com/jesseduffield/lazygit/blob/%s/docs/keybindings", Undoing: "https://github.com/jesseduffield/lazygit/blob/master/docs/Undoing.md", - Config: "https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md", + Config: "https://github.com/jesseduffield/lazygit/blob/%s/docs/Config.md", Tutorial: "https://youtu.be/VDXvbHZYeKY", CustomPatchDemo: "https://github.com/jesseduffield/lazygit#rebase-magic-custom-patches", }, diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index f5672ce64..a1f4c2546 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -68,13 +68,22 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type } func (self *StatusController) GetOnRenderToMain() func() error { + versionStr := "master" + version, err := types.ParseVersionNumber(self.c.GetConfig().GetVersion()) + if err == nil { + // Don't just take the version string as is, but format it again. This + // way it will be correct even if a distribution omits the "v", or the + // ".0" at the end. + versionStr = fmt.Sprintf("v%d.%d.%d", version.Major, version.Minor, version.Patch) + } + return func() error { dashboardString := strings.Join( []string{ lazygitTitle(), "Copyright 2022 Jesse Duffield", - fmt.Sprintf("Keybindings: %s", constants.Links.Docs.Keybindings), - fmt.Sprintf("Config Options: %s", constants.Links.Docs.Config), + fmt.Sprintf("Keybindings: %s", fmt.Sprintf(constants.Links.Docs.Keybindings, versionStr)), + fmt.Sprintf("Config Options: %s", fmt.Sprintf(constants.Links.Docs.Config, versionStr)), fmt.Sprintf("Tutorial: %s", constants.Links.Docs.Tutorial), fmt.Sprintf("Raise an Issue: %s", constants.Links.Issues), fmt.Sprintf("Release Notes: %s", constants.Links.Releases), From 587013392434f3c2a7f7ec2136521a4b4ad72a05 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 19 Mar 2024 10:40:24 +0100 Subject: [PATCH 2/2] Make links in status view clickable, and underline them --- pkg/gui/controllers/status_controller.go | 40 +++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index a1f4c2546..f0289bf3c 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/gui/presentation" @@ -67,6 +68,31 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type return bindings } +func (self *StatusController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { + return []*gocui.ViewMouseBinding{ + { + ViewName: "main", + Key: gocui.MouseLeft, + Handler: self.onClickMain, + }, + } +} + +func (self *StatusController) onClickMain(opts gocui.ViewMouseBindingOpts) error { + view := self.c.Views().Main + + cx, cy := view.Cursor() + url, err := view.Word(cx, cy) + if err == nil && strings.HasPrefix(url, "https://") { + // Ignore errors (opening the link via the OS can fail if the + // `os.openLink` config key references a command that doesn't exist, or + // that errors when called.) + _ = self.c.OS().OpenLink(url) + } + + return nil +} + func (self *StatusController) GetOnRenderToMain() func() error { versionStr := "master" version, err := types.ParseVersionNumber(self.c.GetConfig().GetVersion()) @@ -82,13 +108,13 @@ func (self *StatusController) GetOnRenderToMain() func() error { []string{ lazygitTitle(), "Copyright 2022 Jesse Duffield", - fmt.Sprintf("Keybindings: %s", fmt.Sprintf(constants.Links.Docs.Keybindings, versionStr)), - fmt.Sprintf("Config Options: %s", fmt.Sprintf(constants.Links.Docs.Config, versionStr)), - fmt.Sprintf("Tutorial: %s", constants.Links.Docs.Tutorial), - fmt.Sprintf("Raise an Issue: %s", constants.Links.Issues), - fmt.Sprintf("Release Notes: %s", constants.Links.Releases), - style.FgMagenta.Sprintf("Become a sponsor: %s", constants.Links.Donate), // caffeine ain't free - }, "\n\n") + fmt.Sprintf("Keybindings: %s", style.AttrUnderline.Sprint(fmt.Sprintf(constants.Links.Docs.Keybindings, versionStr))), + fmt.Sprintf("Config Options: %s", style.AttrUnderline.Sprint(fmt.Sprintf(constants.Links.Docs.Config, versionStr))), + fmt.Sprintf("Tutorial: %s", style.AttrUnderline.Sprint(constants.Links.Docs.Tutorial)), + fmt.Sprintf("Raise an Issue: %s", style.AttrUnderline.Sprint(constants.Links.Issues)), + fmt.Sprintf("Release Notes: %s", style.AttrUnderline.Sprint(constants.Links.Releases)), + style.FgMagenta.Sprintf("Become a sponsor: %s", style.AttrUnderline.Sprint(constants.Links.Donate)), // caffeine ain't free + }, "\n\n") + "\n" return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal,