diff options
author | Emil Vanherp <emil@vanherp.me> | 2022-08-20 23:23:03 +0200 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2022-08-26 09:27:49 +0900 |
commit | 4bef330ce15d3ae80959415c24aba4700f5cbe35 (patch) | |
tree | d8147880cf4dc4387d3d6506c89d607e5f018703 /src | |
parent | 8a5f7199649d56a92474676c9cf626204e3e8bcb (diff) |
Add support for ANSI strike-through (#2932)
Close #2932
Co-authored-by: Emil Vanherp <emil@vanherp.me>
Diffstat (limited to 'src')
-rw-r--r-- | src/ansi.go | 5 | ||||
-rw-r--r-- | src/options.go | 2 | ||||
-rw-r--r-- | src/tui/dummy.go | 21 | ||||
-rw-r--r-- | src/tui/light.go | 3 | ||||
-rw-r--r-- | src/tui/tcell.go | 31 | ||||
-rw-r--r-- | src/tui/tcell_test.go | 2 |
6 files changed, 43 insertions, 21 deletions
diff --git a/src/ansi.go b/src/ansi.go index ff12db02..24acc396 100644 --- a/src/ansi.go +++ b/src/ansi.go @@ -55,6 +55,9 @@ func (s *ansiState) ToString() string { if s.attr&tui.Reverse > 0 { ret += "7;" } + if s.attr&tui.StrikeThrough > 0 { + ret += "9;" + } ret += toAnsiString(s.fg, 30) + toAnsiString(s.bg, 40) return "\x1b[" + strings.TrimSuffix(ret, ";") + "m" @@ -376,6 +379,8 @@ func interpretCode(ansiCode string, prevState *ansiState) ansiState { state.attr = state.attr | tui.Blink case 7: state.attr = state.attr | tui.Reverse + case 9: + state.attr = state.attr | tui.StrikeThrough case 23: // tput rmso state.attr = state.attr &^ tui.Italic case 24: // tput rmul diff --git a/src/options.go b/src/options.go index 707efb2d..46bda82c 100644 --- a/src/options.go +++ b/src/options.go @@ -700,6 +700,8 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme { cattr.Attr |= tui.Blink case "reverse": cattr.Attr |= tui.Reverse + case "strikethrough": + cattr.Attr |= tui.StrikeThrough case "black": cattr.Color = tui.Color(0) case "red": diff --git a/src/tui/dummy.go b/src/tui/dummy.go index 686a1009..297a887e 100644 --- a/src/tui/dummy.go +++ b/src/tui/dummy.go @@ -14,16 +14,17 @@ func (a Attr) Merge(b Attr) Attr { const ( AttrUndefined = Attr(0) - AttrRegular = Attr(1 << 7) - AttrClear = Attr(1 << 8) - - Bold = Attr(1) - Dim = Attr(1 << 1) - Italic = Attr(1 << 2) - Underline = Attr(1 << 3) - Blink = Attr(1 << 4) - Blink2 = Attr(1 << 5) - Reverse = Attr(1 << 6) + AttrRegular = Attr(1 << 8) + AttrClear = Attr(1 << 9) + + Bold = Attr(1) + Dim = Attr(1 << 1) + Italic = Attr(1 << 2) + Underline = Attr(1 << 3) + Blink = Attr(1 << 4) + Blink2 = Attr(1 << 5) + Reverse = Attr(1 << 6) + StrikeThrough = Attr(1 << 7) ) func (r *FullscreenRenderer) Init() {} diff --git a/src/tui/light.go b/src/tui/light.go index b4117bce..0546caa8 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -856,6 +856,9 @@ func attrCodes(attr Attr) []string { if (attr & Reverse) > 0 { codes = append(codes, "7") } + if (attr & StrikeThrough) > 0 { + codes = append(codes, "9") + } return codes } diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 6f9b53a9..a873378d 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -8,8 +8,8 @@ import ( "runtime" - "github.com/gdamore/tcell" - "github.com/gdamore/tcell/encoding" + "github.com/gdamore/tcell/v2" + "github.com/gdamore/tcell/v2/encoding" "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" @@ -19,12 +19,20 @@ func HasFullscreenRenderer() bool { return true } +func asTcellColor(color Color) tcell.Color { + value := uint64(tcell.ColorValid) + uint64(color) + if color.is24() { + value = value | uint64(tcell.ColorIsRGB) + } + return tcell.Color(value) +} + func (p ColorPair) style() tcell.Style { style := tcell.StyleDefault - return style.Foreground(tcell.Color(p.Fg())).Background(tcell.Color(p.Bg())) + return style.Foreground(asTcellColor(p.Fg())).Background(asTcellColor(p.Bg())) } -type Attr tcell.Style +type Attr int32 type TcellWindow struct { color bool @@ -72,12 +80,13 @@ func (w *TcellWindow) FinishFill() { } const ( - Bold Attr = Attr(tcell.AttrBold) - Dim = Attr(tcell.AttrDim) - Blink = Attr(tcell.AttrBlink) - Reverse = Attr(tcell.AttrReverse) - Underline = Attr(tcell.AttrUnderline) - Italic = Attr(tcell.AttrItalic) + Bold Attr = Attr(tcell.AttrBold) + Dim = Attr(tcell.AttrDim) + Blink = Attr(tcell.AttrBlink) + Reverse = Attr(tcell.AttrReverse) + Underline = Attr(tcell.AttrUnderline) + StrikeThrough = Attr(tcell.AttrStrikeThrough) + Italic = Attr(tcell.AttrItalic) ) const ( @@ -561,6 +570,7 @@ func (w *TcellWindow) printString(text string, pair ColorPair) { style = style. Reverse(a&Attr(tcell.AttrReverse) != 0). Underline(a&Attr(tcell.AttrUnderline) != 0). + StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0). Italic(a&Attr(tcell.AttrItalic) != 0). Blink(a&Attr(tcell.AttrBlink) != 0). Dim(a&Attr(tcell.AttrDim) != 0) @@ -612,6 +622,7 @@ func (w *TcellWindow) fillString(text string, pair ColorPair) FillReturn { Dim(a&Attr(tcell.AttrDim) != 0). Reverse(a&Attr(tcell.AttrReverse) != 0). Underline(a&Attr(tcell.AttrUnderline) != 0). + StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0). Italic(a&Attr(tcell.AttrItalic) != 0) gr := uniseg.NewGraphemes(text) diff --git a/src/tui/tcell_test.go b/src/tui/tcell_test.go index 96ea7ed3..0d50bb76 100644 --- a/src/tui/tcell_test.go +++ b/src/tui/tcell_test.go @@ -5,7 +5,7 @@ package tui import ( "testing" - "github.com/gdamore/tcell" + "github.com/gdamore/tcell/v2" "github.com/junegunn/fzf/src/util" ) |