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
Provenance
- Commit
4bef330- Tree
d814788- Author
Emil Vanherp <emil@vanherp.me>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
8a5f719
10 files changed+55 added−27 removed
modified:man/man1/fzf.1+2 added-1 removed
19 unmodified lines20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22 THE 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"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 348 unmodified lines377 \fBunderline\fR378 \fBreverse\fR379 \fBdim\fR380 \fBitalic\fR381+ \fBstrikethrough\fR382 383 .B EXAMPLES:384 385 \fB# Seoul256 theme with 8-bit colors649 unmodified linesmodified:src/tui/dummy.go+10 added-9 removed
12 unmodified lines13 }14 15 const (16 AttrUndefined = Attr(0)17- AttrRegular = Attr(1 << 7)18- AttrClear = Attr(1 << 8)17+ AttrRegular = Attr(1 << 8)18+ AttrClear = Attr(1 << 9)19 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)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 )29 30 func (r *FullscreenRenderer) Init() {}31 func (r *FullscreenRenderer) Pause(bool) {}14 unmodified linesmodified:src/tui/light.go+3 added
854 unmodified lines855 }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 }864 865 func colorCodes(fg Color, bg Color) []string {154 unmodified linesmodified:src/tui/tcell_test.go+1 added-1 removed
3 unmodified lines4 5 import (6 "testing"7 8- "github.com/gdamore/tcell"8+ "github.com/gdamore/tcell/v2"9 "github.com/junegunn/fzf/src/util"10 )11 12 func assert(t *testing.T, context string, got interface{}, want interface{}) bool {380 unmodified linesmodified:src/tui/tcell.go+21 added-10 removed
6 unmodified lines7 "time"8 9 "runtime"10 11- "github.com/gdamore/tcell"12- "github.com/gdamore/tcell/encoding"11+ "github.com/gdamore/tcell/v2"12+ "github.com/gdamore/tcell/v2/encoding"13 14 "github.com/mattn/go-runewidth"15 "github.com/rivo/uniseg"16 )1 unmodified line18 func HasFullscreenRenderer() bool {19 return true20 }21 22+func 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+}29+30 func (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 }34 27-type Attr tcell.Style35+type Attr int3236 37 type TcellWindow struct {38 color bool39 preview bool39 unmodified lines79 // NO-OP80 }81 82 const (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 )91 92 const (93 AttrUndefined = Attr(0)475 unmodified lines569 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 lines621 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)627 628 gr := uniseg.NewGraphemes(text)629 for gr.Next() {103 unmodified linesmodified:src/ansi.go+5 added
53 unmodified lines54 }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)62 63 return "\x1b[" + strings.TrimSuffix(ret, ";") + "m"64 }313 unmodified lines378 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.Underline46 unmodified linesmodified:src/options.go+2 added
698 unmodified lines699 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 linesmodified:CHANGELOG.md+5 added
8 unmodified lines9 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+ ```18 19 0.32.120 ------21 - Fixed incorrect ordering of `--tiebreak=chunk`1283 unmodified linesmodified:go.mod+1 added-1 removed
1 module github.com/junegunn/fzf2 3 require (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.013 unmodified linesmodified:go.sum+5 added-5 removed
1 github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=2 github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=3-github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU=4-github.com/gdamore/tcell v1.4.0/go.mod h1:vxEiSDZdW3L+Uhjii9c3375IlDmR05bzxY404ZVSMo0=5-github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=3+github.com/gdamore/tcell/v2 v2.5.3 h1:b9XQrT6QGbgI7JvZOJXFNczOQeIYbo8BfeSMzt2sAV0=4+github.com/gdamore/tcell/v2 v2.5.3/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo=5 github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=6 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=7 github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=8 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=10-github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=9 github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=10 github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=11 github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=12 github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=3 unmodified lines16 github.com/saracen/walker v0.1.2/go.mod h1:0oKYMsKVhSJ+ful4p/XbjvXbMgLEkLITZaxozsl4CGE=17 golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=18 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=19 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=22-golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=20+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=21 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=22 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=23+golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=24 golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 h1:QyVthZKMsyaQwBTJE04jdNN0Pp5Fn9Qga0mrgxyERQM=25 golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=26+golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=27 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=28 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=29 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=30 golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=2 unmodified lines