From 387c6ef664688582ca1be950e2fe260699aa8862 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 14 Aug 2024 23:04:05 +0900 Subject: Support hyperlinks (OSC 8) in the main window Close #2557 --- src/tui/light.go | 6 +++--- src/tui/tcell.go | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/tui') diff --git a/src/tui/light.go b/src/tui/light.go index 187ac667..80488bf7 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -1030,13 +1030,13 @@ func cleanse(str string) string { func (w *LightWindow) CPrint(pair ColorPair, text string) { _, code := w.csiColor(pair.Fg(), pair.Bg(), pair.Attr()) w.stderrInternal(cleanse(text), false, code) - w.csi("m") + w.csi("0m") } func (w *LightWindow) cprint2(fg Color, bg Color, attr Attr, text string) { hasColors, code := w.csiColor(fg, bg, attr) if hasColors { - defer w.csi("m") + defer w.csi("0m") } w.stderrInternal(cleanse(text), false, code) } @@ -1141,7 +1141,7 @@ func (w *LightWindow) CFill(fg Color, bg Color, attr Attr, text string) FillRetu bg = w.bg } if hasColors, resetCode := w.csiColor(fg, bg, attr); hasColors { - defer w.csi("m") + defer w.csi("0m") return w.fill(text, resetCode) } return w.fill(text, w.setBg()) diff --git a/src/tui/tcell.go b/src/tui/tcell.go index d80cd58d..455dcf13 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -604,6 +604,16 @@ func (w *TcellWindow) Print(text string) { w.printString(text, w.normal) } +func (w *TcellWindow) withUrl(style tcell.Style) tcell.Style { + 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]) + } + } + return style +} + func (w *TcellWindow) printString(text string, pair ColorPair) { lx := 0 a := pair.Attr() @@ -618,6 +628,7 @@ func (w *TcellWindow) printString(text string, pair ColorPair) { Blink(a&Attr(tcell.AttrBlink) != 0). Dim(a&Attr(tcell.AttrDim) != 0) } + style = w.withUrl(style) gr := uniseg.NewGraphemes(text) for gr.Next() { @@ -668,13 +679,7 @@ func (w *TcellWindow) fillString(text string, pair ColorPair) FillReturn { Underline(a&Attr(tcell.AttrUnderline) != 0). 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]) - } - } + style = w.withUrl(style) gr := uniseg.NewGraphemes(text) Loop: -- cgit v1.2.3