Skip to content

Commit d11e11d

Browse files
authored
Auto-render hyperlinks (#3914)
- **PR Description** Add a facility to gocui.View to enable auto-rendering of https hyperlinks. Then, use it for the Command Log panel (as an alternative approach to #3911), and also in the status view and in confirmation popups to get rid of some code that used to do this manually. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents c6a7722 + 825f5c0 commit d11e11d

File tree

8 files changed

+75
-96
lines changed

8 files changed

+75
-96
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/integrii/flaggy v1.4.0
1717
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
1818
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
19-
github.com/jesseduffield/gocui v0.3.1-0.20240906064314-bfab49c720d7
19+
github.com/jesseduffield/gocui v0.3.1-0.20240928100326-393cf89a5d3f
2020
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
2121
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
2222
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T
188188
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
189189
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE=
190190
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
191-
github.com/jesseduffield/gocui v0.3.1-0.20240906064314-bfab49c720d7 h1:QeLCKRAt4T6sBg5tSrOc4OojCuAcPxUA+4vNMPY4aH4=
192-
github.com/jesseduffield/gocui v0.3.1-0.20240906064314-bfab49c720d7/go.mod h1:XtEbqCbn45keRXEu+OMZkjN5gw6AEob59afsgHjokZ8=
191+
github.com/jesseduffield/gocui v0.3.1-0.20240928100326-393cf89a5d3f h1:ZzsAUDwPFLPITKLcJpMSqt/3rERdI8YRZKr2l0plrls=
192+
github.com/jesseduffield/gocui v0.3.1-0.20240928100326-393cf89a5d3f/go.mod h1:XtEbqCbn45keRXEu+OMZkjN5gw6AEob59afsgHjokZ8=
193193
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
194194
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
195195
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=

pkg/gui/controllers/helpers/confirmation_helper.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
221221
confirmationView.RenderTextArea()
222222
} else {
223223
self.c.ResetViewOrigin(confirmationView)
224-
self.c.SetViewContent(confirmationView, style.AttrBold.Sprint(underlineLinks(opts.Prompt)))
224+
self.c.SetViewContent(confirmationView, style.AttrBold.Sprint(opts.Prompt))
225225
}
226226

227227
self.setKeyBindings(cancel, opts)
@@ -233,28 +233,6 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
233233
self.c.Context().Push(self.c.Contexts().Confirmation)
234234
}
235235

236-
func underlineLinks(text string) string {
237-
result := ""
238-
remaining := text
239-
for {
240-
linkStart := strings.Index(remaining, "https://")
241-
if linkStart == -1 {
242-
break
243-
}
244-
245-
linkEnd := strings.IndexAny(remaining[linkStart:], " \n>")
246-
if linkEnd == -1 {
247-
linkEnd = len(remaining)
248-
} else {
249-
linkEnd += linkStart
250-
}
251-
underlinedLink := style.PrintSimpleHyperlink(remaining[linkStart:linkEnd])
252-
result += remaining[:linkStart] + underlinedLink
253-
remaining = remaining[linkEnd:]
254-
}
255-
return result + remaining
256-
}
257-
258236
func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) {
259237
var onConfirm func() error
260238
if opts.HandleConfirmPrompt != nil {

pkg/gui/controllers/helpers/confirmation_helper_test.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

pkg/gui/controllers/status_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ func (self *StatusController) showDashboard() {
208208
[]string{
209209
lazygitTitle(),
210210
fmt.Sprintf("Copyright %d Jesse Duffield", time.Now().Year()),
211-
fmt.Sprintf("Keybindings: %s", style.PrintSimpleHyperlink(fmt.Sprintf(constants.Links.Docs.Keybindings, versionStr))),
212-
fmt.Sprintf("Config Options: %s", style.PrintSimpleHyperlink(fmt.Sprintf(constants.Links.Docs.Config, versionStr))),
213-
fmt.Sprintf("Tutorial: %s", style.PrintSimpleHyperlink(constants.Links.Docs.Tutorial)),
214-
fmt.Sprintf("Raise an Issue: %s", style.PrintSimpleHyperlink(constants.Links.Issues)),
215-
fmt.Sprintf("Release Notes: %s", style.PrintSimpleHyperlink(constants.Links.Releases)),
216-
style.FgMagenta.Sprintf("Become a sponsor: %s", style.PrintSimpleHyperlink(constants.Links.Donate)), // caffeine ain't free
211+
fmt.Sprintf("Keybindings: %s", fmt.Sprintf(constants.Links.Docs.Keybindings, versionStr)),
212+
fmt.Sprintf("Config Options: %s", fmt.Sprintf(constants.Links.Docs.Config, versionStr)),
213+
fmt.Sprintf("Tutorial: %s", constants.Links.Docs.Tutorial),
214+
fmt.Sprintf("Raise an Issue: %s", constants.Links.Issues),
215+
fmt.Sprintf("Release Notes: %s", constants.Links.Releases),
216+
style.FgMagenta.Sprintf("Become a sponsor: %s", constants.Links.Donate), // caffeine ain't free
217217
}, "\n\n") + "\n"
218218

219219
self.c.RenderToMainViews(types.RefreshMainOpts{

pkg/gui/views.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (gui *Gui) createAllViews() error {
118118
view.Wrap = true
119119
view.IgnoreCarriageReturns = true
120120
view.UnderlineHyperLinksOnlyOnHover = true
121+
view.AutoRenderHyperLinks = true
121122
}
122123

123124
gui.Views.Staging.Title = gui.c.Tr.UnstagedChanges
@@ -157,6 +158,7 @@ func (gui *Gui) createAllViews() error {
157158

158159
gui.Views.Confirmation.Visible = false
159160
gui.Views.Confirmation.Editor = gocui.EditorFunc(gui.promptEditor)
161+
gui.Views.Confirmation.AutoRenderHyperLinks = true
160162

161163
gui.Views.Suggestions.Visible = false
162164

@@ -171,6 +173,7 @@ func (gui *Gui) createAllViews() error {
171173
gui.Views.Extras.Title = gui.c.Tr.CommandLog
172174
gui.Views.Extras.Autoscroll = true
173175
gui.Views.Extras.Wrap = true
176+
gui.Views.Extras.AutoRenderHyperLinks = true
174177

175178
gui.Views.Snake.Title = gui.c.Tr.SnakeTitle
176179
gui.Views.Snake.FgColor = gocui.ColorGreen

vendor/github.com/jesseduffield/gocui/view.go

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem
172172
github.com/jesseduffield/go-git/v5/utils/merkletrie/index
173173
github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
174174
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
175-
# github.com/jesseduffield/gocui v0.3.1-0.20240906064314-bfab49c720d7
175+
# github.com/jesseduffield/gocui v0.3.1-0.20240928100326-393cf89a5d3f
176176
## explicit; go 1.12
177177
github.com/jesseduffield/gocui
178178
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10

0 commit comments

Comments
 (0)