summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-09-15 14:16:50 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-09-15 14:19:55 +0200
commit041daf9740ee0a459bafb046c74379f094ef64e2 (patch)
tree7947ee153fa11132e6b2fec1c87b5729013d968c
parentf42b6b517acbe62e808aa6e61c93bc604a0ca8c9 (diff)
Use AutoRenderHyperLinks in confirmation viewauto-render-hyper-links
This allows us to get rid of the underlineLinks function.
-rw-r--r--pkg/gui/controllers/helpers/confirmation_helper.go24
-rw-r--r--pkg/gui/controllers/helpers/confirmation_helper_test.go63
-rw-r--r--pkg/gui/views.go1
3 files changed, 2 insertions, 86 deletions
diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go
index 3ffdae6a1..89a150fca 100644
--- a/pkg/gui/controllers/helpers/confirmation_helper.go
+++ b/pkg/gui/controllers/helpers/confirmation_helper.go
@@ -221,7 +221,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
confirmationView.RenderTextArea()
} else {
self.c.ResetViewOrigin(confirmationView)
- self.c.SetViewContent(confirmationView, style.AttrBold.Sprint(underlineLinks(opts.Prompt)))
+ self.c.SetViewContent(confirmationView, style.AttrBold.Sprint(opts.Prompt))
}
self.setKeyBindings(cancel, opts)
@@ -233,28 +233,6 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
self.c.Context().Push(self.c.Contexts().Confirmation)
}
-func underlineLinks(text string) string {
- result := ""
- remaining := text
- for {
- linkStart := strings.Index(remaining, "https://")
- if linkStart == -1 {
- break
- }
-
- linkEnd := strings.IndexAny(remaining[linkStart:], " \n>")
- if linkEnd == -1 {
- linkEnd = len(remaining)
- } else {
- linkEnd += linkStart
- }
- underlinedLink := style.PrintSimpleHyperlink(remaining[linkStart:linkEnd])
- result += remaining[:linkStart] + underlinedLink
- remaining = remaining[linkEnd:]
- }
- return result + remaining
-}
-
func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) {
var onConfirm func() error
if opts.HandleConfirmPrompt != nil {
diff --git a/pkg/gui/controllers/helpers/confirmation_helper_test.go b/pkg/gui/controllers/helpers/confirmation_helper_test.go
deleted file mode 100644
index de3db9358..000000000
--- a/pkg/gui/controllers/helpers/confirmation_helper_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-package helpers
-
-import (
- "testing"
-
- "github.com/gookit/color"
- "github.com/stretchr/testify/assert"
- "github.com/xo/terminfo"
-)
-
-func Test_underlineLinks(t *testing.T) {
- scenarios := []struct {
- name string
- text string
- expectedResult string
- }{
- {
- name: "empty string",
- text: "",
- expectedResult: "",
- },
- {
- name: "no links",
- text: "abc",
- expectedResult: "abc",
- },
- {
- name: "entire string is a link",
- text: "https://example.com",
- expectedResult: "\x1b]8;;https://example.com\x1b\\https://example.com\x1b]8;;\x1b\\",
- },
- {
- name: "link preceded and followed by text",
- text: "bla https://example.com xyz",
- expectedResult: "bla \x1b]8;;https://example.com\x1b\\https://example.com\x1b]8;;\x1b\\ xyz",
- },
- {
- name: "more than one link",
- text: "bla https://link1 blubb https://link2 xyz",
- expectedResult: "bla \x1b]8;;https://link1\x1b\\https://link1\x1b]8;;\x1b\\ blubb \x1b]8;;https://link2\x1b\\https://link2\x1b]8;;\x1b\\ xyz",
- },
- {
- name: "link in angle brackets",
- text: "See <https://example.com> for details",
- expectedResult: "See <\x1b]8;;https://example.com\x1b\\https://example.com\x1b]8;;\x1b\\> for details",
- },
- {
- name: "link followed by newline",
- text: "URL: https://example.com\nNext line",
- expectedResult: "URL: \x1b]8;;https://example.com\x1b\\https://example.com\x1b]8;;\x1b\\\nNext line",
- },
- }
-
- oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions)
- defer color.ForceSetColorLevel(oldColorLevel)
-
- for _, s := range scenarios {
- t.Run(s.name, func(t *testing.T) {
- result := underlineLinks(s.text)
- assert.Equal(t, s.expectedResult, result)
- })
- }
-}
diff --git a/pkg/gui/views.go b/pkg/gui/views.go
index c7b5e40ff..526696b25 100644
--- a/pkg/gui/views.go
+++ b/pkg/gui/views.go
@@ -158,6 +158,7 @@ func (gui *Gui) createAllViews() error {
gui.Views.Confirmation.Visible = false
gui.Views.Confirmation.Editor = gocui.EditorFunc(gui.promptEditor)
+ gui.Views.Confirmation.AutoRenderHyperLinks = true
gui.Views.Suggestions.Visible = false