m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 15:53:39 -05:00

Add support for hyperlinks in preview window

Close #2165
This commit is contained in:
Junegunn Choi
2024-08-14 08:43:27 +09:00
parent 2c8a96bb27
commit d90a969c00
6 changed files with 80 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ package tui
import (
"os"
"regexp"
"time"
"github.com/gdamore/tcell/v2"
@@ -49,6 +50,8 @@ type TcellWindow struct {
lastY int
moveCursor bool
borderStyle BorderStyle
uri *string
params *string
}
func (w *TcellWindow) Top() int {
@@ -666,6 +669,13 @@ func (w *TcellWindow) fillString(text string, pair ColorPair) FillReturn {
StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).
Italic(a&Attr(tcell.AttrItalic) != 0)
if w.uri != nil {
style = style.Url(*w.uri)
if md := regexp.MustCompile(`id=([^:]+)`).FindStringSubmatch(*w.params); len(md) > 1 {
style = style.UrlId(md[1])
}
}
gr := uniseg.NewGraphemes(text)
Loop:
for gr.Next() {
@@ -716,6 +726,16 @@ func (w *TcellWindow) Fill(str string) FillReturn {
return w.fillString(str, w.normal)
}
func (w *TcellWindow) LinkBegin(uri string, params string) {
w.uri = &uri
w.params = &params
}
func (w *TcellWindow) LinkEnd() {
w.uri = nil
w.params = nil
}
func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
if fg == colDefault {
fg = w.normal.Fg()