Skip to content
Myr

Add support for ANSI strike-through (#2932)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #2932

authored by Emil Vanherp · committed by Junegunn Choi · parent 8a5f719 · Browse files · 10 files+55 added−27 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Emil Vanherp <emil@vanherp.me>

Diff stats

10 files+55 added−27 removed

  • other:+55 added−27 removed

10 files+55 added−27 removed

modified:man/man1/fzf.1+2 added-1 removed
19 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Aug 2022" "fzf 0.32.1" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Aug 2022" "fzf 0.32.2" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
348 unmodified lines
377 \fBunderline\fR378 \fBreverse\fR379 \fBdim\fR380 \fBitalic\fR381 \fBstrikethrough\fR382383.B EXAMPLES:384385 \fB# Seoul256 theme with 8-bit colors
649 unmodified lines
modified:src/tui/dummy.go+10 added-9 removed
12 unmodified lines
13}1415const (16 AttrUndefined = Attr(0)17 AttrRegular = Attr(1 << 7)18 AttrClear = Attr(1 << 8)17 AttrRegular = Attr(1 << 8)18 AttrClear = Attr(1 << 9)1920 Bold = Attr(1)21 Dim = Attr(1 << 1)22 Italic = Attr(1 << 2)23 Underline = Attr(1 << 3)24 Blink = Attr(1 << 4)25 Blink2 = Attr(1 << 5)26 Reverse = Attr(1 << 6)20 Bold = Attr(1)21 Dim = Attr(1 << 1)22 Italic = Attr(1 << 2)23 Underline = Attr(1 << 3)24 Blink = Attr(1 << 4)25 Blink2 = Attr(1 << 5)26 Reverse = Attr(1 << 6)27 StrikeThrough = Attr(1 << 7)28)2930func (r *FullscreenRenderer) Init() {}31func (r *FullscreenRenderer) Pause(bool) {}
14 unmodified lines
modified:src/tui/light.go+3 added
854 unmodified lines
855 }856 if (attr & Reverse) > 0 {857 codes = append(codes, "7")858 }859 if (attr & StrikeThrough) > 0 {860 codes = append(codes, "9")861 }862 return codes863}864865func colorCodes(fg Color, bg Color) []string {
154 unmodified lines
modified:src/tui/tcell_test.go+1 added-1 removed
3 unmodified lines
45import (6 "testing"78 "github.com/gdamore/tcell"8 "github.com/gdamore/tcell/v2"9 "github.com/junegunn/fzf/src/util"10)1112func assert(t *testing.T, context string, got interface{}, want interface{}) bool {
380 unmodified lines
modified:src/tui/tcell.go+21 added-10 removed
6 unmodified lines
7 "time"89 "runtime"1011 "github.com/gdamore/tcell"12 "github.com/gdamore/tcell/encoding"11 "github.com/gdamore/tcell/v2"12 "github.com/gdamore/tcell/v2/encoding"1314 "github.com/mattn/go-runewidth"15 "github.com/rivo/uniseg"16)
1 unmodified line
18func HasFullscreenRenderer() bool {19 return true20}2122func asTcellColor(color Color) tcell.Color {23 value := uint64(tcell.ColorValid) + uint64(color)24 if color.is24() {25 value = value | uint64(tcell.ColorIsRGB)26 }27 return tcell.Color(value)28}2930func (p ColorPair) style() tcell.Style {31 style := tcell.StyleDefault24 return style.Foreground(tcell.Color(p.Fg())).Background(tcell.Color(p.Bg()))32 return style.Foreground(asTcellColor(p.Fg())).Background(asTcellColor(p.Bg()))33}3427type Attr tcell.Style35type Attr int323637type TcellWindow struct {38 color bool39 preview bool
39 unmodified lines
79 // NO-OP80}8182const (75 Bold Attr = Attr(tcell.AttrBold)76 Dim = Attr(tcell.AttrDim)77 Blink = Attr(tcell.AttrBlink)78 Reverse = Attr(tcell.AttrReverse)79 Underline = Attr(tcell.AttrUnderline)80 Italic = Attr(tcell.AttrItalic)83 Bold Attr = Attr(tcell.AttrBold)84 Dim = Attr(tcell.AttrDim)85 Blink = Attr(tcell.AttrBlink)86 Reverse = Attr(tcell.AttrReverse)87 Underline = Attr(tcell.AttrUnderline)88 StrikeThrough = Attr(tcell.AttrStrikeThrough)89 Italic = Attr(tcell.AttrItalic)90)9192const (93 AttrUndefined = Attr(0)
475 unmodified lines
569 if a&AttrClear == 0 {570 style = style.571 Reverse(a&Attr(tcell.AttrReverse) != 0).572 Underline(a&Attr(tcell.AttrUnderline) != 0).573 StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).574 Italic(a&Attr(tcell.AttrItalic) != 0).575 Blink(a&Attr(tcell.AttrBlink) != 0).576 Dim(a&Attr(tcell.AttrDim) != 0)577 }
43 unmodified lines
621 Bold(a&Attr(tcell.AttrBold) != 0).622 Dim(a&Attr(tcell.AttrDim) != 0).623 Reverse(a&Attr(tcell.AttrReverse) != 0).624 Underline(a&Attr(tcell.AttrUnderline) != 0).625 StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).626 Italic(a&Attr(tcell.AttrItalic) != 0)627628 gr := uniseg.NewGraphemes(text)629 for gr.Next() {
103 unmodified lines
modified:src/ansi.go+5 added
53 unmodified lines
54 }55 if s.attr&tui.Reverse > 0 {56 ret += "7;"57 }58 if s.attr&tui.StrikeThrough > 0 {59 ret += "9;"60 }61 ret += toAnsiString(s.fg, 30) + toAnsiString(s.bg, 40)6263 return "\x1b[" + strings.TrimSuffix(ret, ";") + "m"64}
313 unmodified lines
378 case 5:379 state.attr = state.attr | tui.Blink380 case 7:381 state.attr = state.attr | tui.Reverse382 case 9:383 state.attr = state.attr | tui.StrikeThrough384 case 23: // tput rmso385 state.attr = state.attr &^ tui.Italic386 case 24: // tput rmul387 state.attr = state.attr &^ tui.Underline
46 unmodified lines
modified:src/options.go+2 added
698 unmodified lines
699 case "blink":700 cattr.Attr |= tui.Blink701 case "reverse":702 cattr.Attr |= tui.Reverse703 case "strikethrough":704 cattr.Attr |= tui.StrikeThrough705 case "black":706 cattr.Color = tui.Color(0)707 case "red":708 cattr.Color = tui.Color(1)
1079 unmodified lines
modified:CHANGELOG.md+5 added
8 unmodified lines
9 printf "\e[38:5:208mOption 1\e[m\nOption 2" | fzf --ansi10 ```11- Support `border-{up,down}` as the synonyms for `border-{top,bottom}` in12 `--preview-window`13- Added support for ANSI `strikethrough`14 ```sh15 printf "\e[9mdeleted" | fzf --ansi16 fzf --color fg+:strikethrough17 ```18190.32.120------21- Fixed incorrect ordering of `--tiebreak=chunk`
1283 unmodified lines
modified:go.mod+1 added-1 removed
1module github.com/junegunn/fzf23require (4 github.com/gdamore/tcell v1.4.04 github.com/gdamore/tcell/v2 v2.5.35 github.com/mattn/go-isatty v0.0.146 github.com/mattn/go-runewidth v0.0.137 github.com/mattn/go-shellwords v1.0.128 github.com/rivo/uniseg v0.2.0
13 unmodified lines
modified:go.sum+5 added-5 removed
1github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=2github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=3github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=4github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=5github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=3github.com/gdamore/tcell/v2 v2.5.3 h1:b9XQrT6QGbgI7JvZOJXFNczOQeIYbo8BfeSMzt2sAV0=4github.com/gdamore/tcell/v2 v2.5.3/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo=5github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=6github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=7github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=8github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=10github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=9github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=10github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=11github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=12github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
3 unmodified lines
16github.com/saracen/walker v0.1.2/go.mod h1:0oKYMsKVhSJ+ful4p/XbjvXbMgLEkLITZaxozsl4CGE=17golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=18golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=19golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=22golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=20golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=21golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=22golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=23golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=24golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 h1:QyVthZKMsyaQwBTJE04jdNN0Pp5Fn9Qga0mrgxyERQM=25golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=26golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=27golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=28golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=29golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=30golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
2 unmodified lines