Support hyperlinks (OSC 8) in the main window
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #2557
authored by Junegunn Choi · committed by Junegunn Choi · parent 581734c · Browse files · 5 files·+41 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+41 added−13 removed
- other:+41 added−13 removed
Provenance
- Commit
387c6ef- Tree
4478ab1- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
581734c
5 files changed+41 added−13 removed
modified:src/tui/light.go+3 added-3 removed
1028 unmodified lines1029 1030 func (w *LightWindow) CPrint(pair ColorPair, text string) {1031 _, code := w.csiColor(pair.Fg(), pair.Bg(), pair.Attr())1032 w.stderrInternal(cleanse(text), false, code)1033- w.csi("m")1033+ w.csi("0m")1034 }1035 1036 func (w *LightWindow) cprint2(fg Color, bg Color, attr Attr, text string) {1037 hasColors, code := w.csiColor(fg, bg, attr)1038 if hasColors {1039- defer w.csi("m")1039+ defer w.csi("0m")1040 }1041 w.stderrInternal(cleanse(text), false, code)1042 }1043 96 unmodified lines1140 if bg == colDefault {1141 bg = w.bg1142 }1143 if hasColors, resetCode := w.csiColor(fg, bg, attr); hasColors {1144- defer w.csi("m")1144+ defer w.csi("0m")1145 return w.fill(text, resetCode)1146 }1147 return w.fill(text, w.setBg())1148 }20 unmodified linesmodified:src/tui/tcell.go+12 added-7 removed
602 unmodified lines603 func (w *TcellWindow) Print(text string) {604 w.printString(text, w.normal)605 }606 607+func (w *TcellWindow) withUrl(style tcell.Style) tcell.Style {608+ if w.uri != nil {609+ style = style.Url(*w.uri)610+ if md := regexp.MustCompile(`id=([^:]+)`).FindStringSubmatch(*w.params); len(md) > 1 {611+ style = style.UrlId(md[1])612+ }613+ }614+ return style615+}616+617 func (w *TcellWindow) printString(text string, pair ColorPair) {618 lx := 0619 a := pair.Attr()620 6 unmodified lines627 Italic(a&Attr(tcell.AttrItalic) != 0).628 Blink(a&Attr(tcell.AttrBlink) != 0).629 Dim(a&Attr(tcell.AttrDim) != 0)630 }631+ style = w.withUrl(style)632 633 gr := uniseg.NewGraphemes(text)634 for gr.Next() {635 st := style42 unmodified lines678 Reverse(a&Attr(tcell.AttrReverse) != 0).679 Underline(a&Attr(tcell.AttrUnderline) != 0).680 StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).681 Italic(a&Attr(tcell.AttrItalic) != 0)682+ style = w.withUrl(style)683 672- if w.uri != nil {673- style = style.Url(*w.uri)674- if md := regexp.MustCompile(`id=([^:]+)`).FindStringSubmatch(*w.params); len(md) > 1 {675- style = style.UrlId(md[1])676- }677- }678-684 gr := uniseg.NewGraphemes(text)685 Loop:686 for gr.Next() {687 st := style145 unmodified linesmodified:src/result.go+8 added-3 removed
14 unmodified lines15 type colorOffset struct {16 offset [2]int3217 color tui.ColorPair18 match bool19+ url *url20 }21 22 type Result struct {23 item *Item153 unmodified lines177 add := func(idx int) {178 if curr != 0 && idx > start {179 if curr < 0 {180 color := colMatch181+ var url *url182 if curr < -1 && theme.Colored {183+ ansi := itemColors[-curr-2]184+ url = ansi.color.url181- origColor := ansiToColorPair(itemColors[-curr-2], colMatch)185+ origColor := ansiToColorPair(ansi, colMatch)186 // hl or hl+ only sets the foreground color, so colMatch is the187 // combination of either [hl and bg] or [hl+ and bg+].188 //189 // If the original text already has background color, and the7 unmodified lines197 color = origColor.MergeNonDefault(color)198 }199 }200 colors = append(colors, colorOffset{197- offset: [2]int32{int32(start), int32(idx)}, color: color, match: true})201+ offset: [2]int32{int32(start), int32(idx)}, color: color, match: true, url: url})202 } else {203 ansi := itemColors[curr-1]204 colors = append(colors, colorOffset{205 offset: [2]int32{int32(start), int32(idx)},206 color: ansiToColorPair(ansi, colBase),203- match: false})207+ match: false,208+ url: ansi.color.url})209 }210 }211 }212 for idx, col := range cols {56 unmodified linesmodified:src/terminal.go+12 added
2458 unmodified lines2459 var index int322460 var substr string2461 var prefixWidth int2462 maxOffset := int32(len(text))2463+ var url *url2464 for _, offset := range offsets {2465 b := util.Constrain32(offset.offset[0], index, maxOffset)2466 e := util.Constrain32(offset.offset[1], index, maxOffset)2467+ if url != nil && offset.url == nil {2468+ url = nil2469+ window.LinkEnd()2470+ }2471 2472 substr, prefixWidth = t.processTabs(text[index:b], prefixWidth)2473 window.CPrint(colBase, substr)2474 2475 if b < e {2476 substr, prefixWidth = t.processTabs(text[b:e], prefixWidth)2477+ if url == nil && offset.url != nil {2478+ url = offset.url2479+ window.LinkBegin(url.uri, url.params)2480+ }2481 window.CPrint(offset.color, substr)2482 }2483 2484 index = e2485 if index >= maxOffset {2486 break2487 }2488 }2489+ if url != nil {2490+ window.LinkEnd()2491+ }2492 if index < maxOffset {2493 substr, _ = t.processTabs(text[index:], prefixWidth)2494 window.CPrint(colBase, substr)2495 }2575 unmodified linesmodified:CHANGELOG.md+6 added
15 unmodified lines16 --info=inline-right # Show info on the right side of the prompt line17 # ...18 '19 ```20+- Hyperlinks (OSC 8) are now supported in the preview window and in the main window21+ ```sh22+ printf '<< \e]8;;http://github.com/junegunn/fzf\e\\Link to \e[32mfz\e[0mf\e]8;;\e\\ >>' | fzf --ansi23+24+ fzf --preview "printf '<< \e]8;;http://github.com/junegunn/fzf\e\\Link to \e[32mfz\e[0mf\e]8;;\e\\ >>'"25+ ```26 - Fixed `--tmux bottom` when the status line is not at the bottom27 - Fixed extra scroll offset in multi-line mode (`--read0` or `--wrap`)28 - Added fallback `ps` command for `kill` completion on Cygwin29 2240 unmodified lines