Add support for text styling using --color
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #1663
authored by Junegunn Choi · committed by Junegunn Choi · parent 03c4f04 · Browse files · 12 files·+498 added−343 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+498 added−343 removed
- other:+498 added−343 removed
Provenance
- Commit
11841f6- Tree
25732a5- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
03c4f04
12 files changed+498 added−343 removed
modified:man/man1/fzf.1+18 added-6 removed
265 unmodified lines266 .TP267 .BI "--tabstop=" SPACES268 Number of spaces for a tab character (default: 8)269 .TP270-.BI "--color=" "[BASE_SCHEME][,COLOR:ANSI]"270+.BI "--color=" "[BASE_SCHEME][,COLOR_NAME[:ANSI_COLOR][:ANSI_ATTRIBUTES]]..."271 Color configuration. The name of the base color scheme is followed by custom272-color mappings. Ansi color code of -1 denotes terminal default273-foreground/background color. You can also specify 24-bit color in \fB#rrggbb\fR274-format.272+color mappings.273 274 .RS275 .B BASE SCHEME:276 (default: dark on 256-color terminal, otherwise 16)2 unmodified lines279 \fBlight \fRColor scheme for light 256-color terminal280 \fB16 \fRColor scheme for 16-color terminal281 \fBbw \fRNo colors (equivalent to \fB--no-color\fR)282 285-.B COLOR:283+.B COLOR NAMES:284 \fBfg \fRText285 \fBbg \fRBackground286 \fBpreview-fg \fRPreview window text287 \fBpreview-bg \fRPreview window background9 unmodified lines297 \fBmarker \fRMulti-select marker298 \fBspinner \fRStreaming input indicator299 \fBheader \fRHeader300 301+.B ANSI COLORS:302+ \fB-1 \fRDefault terminal foreground/background color303+ \fB \fR(or the original color of the text)304+ \fB0 ~ 15 \fR16 base colors305+ \fB16 ~ 255 \fRANSI 256 colors306+ \fB#rrggbb \fR24-bit colors307+308+.B ANSI ATTRIBUTES: (Only applies to foreground colors)309+ \fBregular \fRClears previously set attributes; should precede the other ones310+ \fBbold\fR311+ \fBunderline\fR312+ \fBitalic\fR313+ \fBreverse\fR314+315 .B EXAMPLES:316 317 \fB# Seoul256 theme with 8-bit colors306- # (https://github.com/junegunn/seoul256.vim) 318+ # (https://github.com/junegunn/seoul256.vim)319 fzf --color='bg:237,bg+:236,info:143,border:240,spinner:108' \\320 --color='hl:65,fg:252,header:65,fg+:252' \\321 --color='pointer:161,marker:168,prompt:110,hl+:108'322 553 unmodified linesmodified:src/tui/dummy.go+11 added-8 removed
13 unmodified lines14 return a | b15 }16 17 const (18+ AttrUndefined = Attr(0)19+ AttrRegular = Attr(1 << 7)20+ AttrClear = Attr(1 << 8)18- AttrRegular Attr = Attr(0)19- Bold = Attr(1)20- Dim = Attr(1 << 1)21- Italic = Attr(1 << 2)22- Underline = Attr(1 << 3)23- Blink = Attr(1 << 4)24- Blink2 = Attr(1 << 5)25- Reverse = Attr(1 << 6)21+22+ Bold = Attr(1)23+ Dim = Attr(1 << 1)24+ Italic = Attr(1 << 2)25+ Underline = Attr(1 << 3)26+ Blink = Attr(1 << 4)27+ Blink2 = Attr(1 << 5)28+ Reverse = Attr(1 << 6)29 )30 31 func (r *FullscreenRenderer) Init() {}32 func (r *FullscreenRenderer) Pause(bool) {}14 unmodified linesmodified:src/tui/light.go+19 added-24 removed
625 unmodified lines626 627 func (r *LightRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {628 w := &LightWindow{629 renderer: r,630- colored: r.theme != nil,630+ colored: r.theme.Colored,631 preview: preview,632 border: borderStyle,633 top: top,634 left: left,1 unmodified line636 height: height,637 tabstop: r.tabstop,638 fg: colDefault,639 bg: colDefault}640- if r.theme != nil {641- if preview {642- w.fg = r.theme.PreviewFg643- w.bg = r.theme.PreviewBg644- } else {645- w.fg = r.theme.Fg646- w.bg = r.theme.Bg640+ if preview {641+ w.fg = r.theme.PreviewFg.Color642+ w.bg = r.theme.PreviewBg.Color643+ } else {644+ w.fg = r.theme.Fg.Color645+ w.bg = r.theme.Bg.Color647- }646 }647 w.drawBorder()648 return w649 }8 unmodified lines658 }659 660 func (w *LightWindow) drawBorderHorizontal() {661 w.Move(0, 0)664- w.CPrint(ColBorder, AttrRegular, repeat(w.border.horizontal, w.width))662+ w.CPrint(ColBorder, repeat(w.border.horizontal, w.width))663 w.Move(w.height-1, 0)666- w.CPrint(ColBorder, AttrRegular, repeat(w.border.horizontal, w.width))664+ w.CPrint(ColBorder, repeat(w.border.horizontal, w.width))665 }666 667 func (w *LightWindow) drawBorderAround() {668 w.Move(0, 0)669 color := ColBorder670 if w.preview {671 color = ColPreviewBorder672 }675- w.CPrint(color, AttrRegular,676- string(w.border.topLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.topRight))673+ w.CPrint(color, string(w.border.topLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.topRight))674 for y := 1; y < w.height-1; y++ {675 w.Move(y, 0)679- w.CPrint(color, AttrRegular, string(w.border.vertical))680- w.CPrint(color, AttrRegular, repeat(' ', w.width-2))681- w.CPrint(color, AttrRegular, string(w.border.vertical))676+ w.CPrint(color, string(w.border.vertical))677+ w.CPrint(color, repeat(' ', w.width-2))678+ w.CPrint(color, string(w.border.vertical))679 }680 w.Move(w.height-1, 0)684- w.CPrint(color, AttrRegular,685- string(w.border.bottomLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.bottomRight))681+ w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.bottomRight))682 }683 684 func (w *LightWindow) csi(code string) {685 w.renderer.csi(code)54 unmodified lines740 }741 742 func attrCodes(attr Attr) []string {743 codes := []string{}744+ if (attr & AttrClear) > 0 {745+ return codes746+ }747 if (attr & Bold) > 0 {748 codes = append(codes, "1")749 }750 if (attr & Dim) > 0 {51 unmodified lines802 func cleanse(str string) string {803 return strings.Replace(str, "\x1b", "", -1)804 }805 807-func (w *LightWindow) CPrint(pair ColorPair, attr Attr, text string) {808- if !w.colored {809- w.csiColor(colDefault, colDefault, attrFor(pair, attr))810- } else {811- w.csiColor(pair.Fg(), pair.Bg(), attr)812- }806+func (w *LightWindow) CPrint(pair ColorPair, text string) {807+ w.csiColor(pair.Fg(), pair.Bg(), pair.Attr())808 w.stderrInternal(cleanse(text), false)809 w.csi("m")810 }811 103 unmodified linesmodified:src/tui/tcell.go+20 added-21 removed
75 unmodified lines76 Dim = Attr(tcell.AttrDim)77 Blink = Attr(tcell.AttrBlink)78 Reverse = Attr(tcell.AttrReverse)79 Underline = Attr(tcell.AttrUnderline)80- Italic = Attr(tcell.AttrNone) // Not supported80+ Italic = Attr(tcell.AttrItalic)81 )82 83 const (84- AttrRegular Attr = 084+ AttrUndefined = Attr(0)85+ AttrRegular = Attr(1 << 7)86+ AttrClear = Attr(1 << 8)87 )88 89 func (r *FullscreenRenderer) defaultTheme() *ColorTheme {90 if _screen.Colors() >= 256 {324 unmodified lines415 if preview {416 normal = ColPreview417 }418 return &TcellWindow{417- color: r.theme != nil,419+ color: r.theme.Colored,420 preview: preview,421 top: top,422 left: left,423 width: width,37 unmodified lines461 w.lastX = x462 }463 464 func (w *TcellWindow) Print(text string) {463- w.printString(text, w.normal, 0)465+ w.printString(text, w.normal)466 }467 466-func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {468+func (w *TcellWindow) printString(text string, pair ColorPair) {469 t := text470 lx := 0471+ a := pair.Attr()472 470- var style tcell.Style471- if w.color {472- style = pair.style().473+ style := pair.style()474+ if a&AttrClear == 0 {475+ style = style.476 Reverse(a&Attr(tcell.AttrReverse) != 0).474- Underline(a&Attr(tcell.AttrUnderline) != 0)475- } else {476- style = w.normal.style().477- Reverse(a&Attr(tcell.AttrReverse) != 0 || pair == ColCurrent || pair == ColCurrentMatch).478- Underline(a&Attr(tcell.AttrUnderline) != 0 || pair == ColMatch || pair == ColCurrentMatch)477+ Underline(a&Attr(tcell.AttrUnderline) != 0).478+ Italic(a&Attr(tcell.AttrItalic) != 0).479+ Blink(a&Attr(tcell.AttrBlink) != 0).480+ Dim(a&Attr(tcell.AttrDim) != 0)481 }480- style = style.481- Blink(a&Attr(tcell.AttrBlink) != 0).482- Bold(a&Attr(tcell.AttrBold) != 0).483- Dim(a&Attr(tcell.AttrDim) != 0)482 483 for {484 if len(t) == 0 {485 break24 unmodified lines510 }511 w.lastX += lx512 }513 516-func (w *TcellWindow) CPrint(pair ColorPair, attr Attr, text string) {517- w.printString(text, pair, attr)514+func (w *TcellWindow) CPrint(pair ColorPair, text string) {515+ w.printString(text, pair)516 }517 518 func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn {519 lx := 08 unmodified lines528 Blink(a&Attr(tcell.AttrBlink) != 0).529 Bold(a&Attr(tcell.AttrBold) != 0).530 Dim(a&Attr(tcell.AttrDim) != 0).531 Reverse(a&Attr(tcell.AttrReverse) != 0).534- Underline(a&Attr(tcell.AttrUnderline) != 0)532+ Underline(a&Attr(tcell.AttrUnderline) != 0).533+ Italic(a&Attr(tcell.AttrItalic) != 0)534 535 for _, r := range text {536 if r == '\n' {537 w.lastY++34 unmodified lines572 }573 if bg == colDefault {574 bg = w.normal.Bg()575 }577- return w.fillString(str, NewColorPair(fg, bg), a)576+ return w.fillString(str, NewColorPair(fg, bg, a), a)577 }578 579 func (w *TcellWindow) drawBorder() {580 if w.borderStyle.shape == BorderNone {36 unmodified linesmodified:src/tui/tui.go+213 added-159 removed
121 unmodified lines122 func (c Color) is24() bool {123 return c > 0 && (c&(1<<24)) > 0124 }125 126+type ColorAttr struct {127+ Color Color128+ Attr Attr129+}130+131+func NewColorAttr() ColorAttr {132+ return ColorAttr{Color: colUndefined, Attr: AttrUndefined}133+}134+135 const (136 colUndefined Color = -2137 colDefault Color = -1138 )17 unmodified lines156 FillSuspend157 )158 159 type ColorPair struct {151- fg Color152- bg Color153- id int160+ fg Color161+ bg Color162+ attr Attr163 }164 165 func HexToColor(rrggbb string) Color {166 r, _ := strconv.ParseInt(rrggbb[1:3], 16, 0)1 unmodified line168 b, _ := strconv.ParseInt(rrggbb[5:7], 16, 0)169 return Color((1 << 24) + (r << 16) + (g << 8) + b)170 }171 163-func NewColorPair(fg Color, bg Color) ColorPair {164- return ColorPair{fg, bg, -1}172+func NewColorPair(fg Color, bg Color, attr Attr) ColorPair {173+ return ColorPair{fg, bg, attr}174 }175 176 func (p ColorPair) Fg() Color {177 return p.fg2 unmodified lines180 func (p ColorPair) Bg() Color {181 return p.bg182 }183 184+func (p ColorPair) Attr() Attr {185+ return p.attr186+}187+188+func (p ColorPair) merge(other ColorPair, except Color) ColorPair {189+ dup := p190+ dup.attr = dup.attr.Merge(other.attr)191+ if other.fg != except {192+ dup.fg = other.fg193+ }194+ if other.bg != except {195+ dup.bg = other.bg196+ }197+ return dup198+}199+200+func (p ColorPair) WithAttr(attr Attr) ColorPair {201+ dup := p202+ dup.attr = dup.attr.Merge(attr)203+ return dup204+}205+206+func (p ColorPair) MergeAttr(other ColorPair) ColorPair {207+ return p.WithAttr(other.attr)208+}209+210+func (p ColorPair) Merge(other ColorPair) ColorPair {211+ return p.merge(other, colUndefined)212+}213+214+func (p ColorPair) MergeNonDefault(other ColorPair) ColorPair {215+ return p.merge(other, colDefault)216+}217+218 type ColorTheme struct {219+ Colored bool220+ Input ColorAttr176- Fg Color177- Bg Color178- PreviewFg Color179- PreviewBg Color180- DarkBg Color181- Gutter Color182- Prompt Color183- Match Color184- Current Color185- CurrentMatch Color186- Spinner Color187- Info Color188- Cursor Color189- Selected Color190- Header Color191- Border Color221+ Fg ColorAttr222+ Bg ColorAttr223+ PreviewFg ColorAttr224+ PreviewBg ColorAttr225+ DarkBg ColorAttr226+ Gutter ColorAttr227+ Prompt ColorAttr228+ Match ColorAttr229+ Current ColorAttr230+ CurrentMatch ColorAttr231+ Spinner ColorAttr232+ Info ColorAttr233+ Cursor ColorAttr234+ Selected ColorAttr235+ Header ColorAttr236+ Border ColorAttr237 }238 239 type Event struct {240 Type int110 unmodified lines351 352 Move(y int, x int)353 MoveAndClear(y int, x int)354 Print(text string)310- CPrint(color ColorPair, attr Attr, text string)355+ CPrint(color ColorPair, text string)356 Fill(text string) FillReturn357 CFill(fg Color, bg Color, attr Attr, text string) FillReturn358 Erase()359 }20 unmodified lines380 Default16 *ColorTheme381 Dark256 *ColorTheme382 Light256 *ColorTheme383 339- ColPrompt ColorPair340- ColNormal ColorPair341- ColMatch ColorPair342- ColCursor ColorPair343- ColSelected ColorPair344- ColCurrent ColorPair345- ColCurrentMatch ColorPair346- ColCurrentCursor ColorPair347- ColCurrentSelected ColorPair348- ColSpinner ColorPair349- ColInfo ColorPair350- ColHeader ColorPair351- ColBorder ColorPair352- ColPreview ColorPair353- ColPreviewBorder ColorPair384+ ColPrompt ColorPair385+ ColNormal ColorPair386+ ColInput ColorPair387+ ColMatch ColorPair388+ ColCursor ColorPair389+ ColCursorEmpty ColorPair390+ ColSelected ColorPair391+ ColCurrent ColorPair392+ ColCurrentMatch ColorPair393+ ColCurrentCursor ColorPair394+ ColCurrentCursorEmpty ColorPair395+ ColCurrentSelected ColorPair396+ ColCurrentSelectedEmpty ColorPair397+ ColSpinner ColorPair398+ ColInfo ColorPair399+ ColHeader ColorPair400+ ColBorder ColorPair401+ ColPreview ColorPair402+ ColPreviewBorder ColorPair403 )404 405 func EmptyTheme() *ColorTheme {406 return &ColorTheme{358- Fg: colUndefined,359- Bg: colUndefined,360- PreviewFg: colUndefined,361- PreviewBg: colUndefined,362- DarkBg: colUndefined,363- Gutter: colUndefined,364- Prompt: colUndefined,365- Match: colUndefined,366- Current: colUndefined,367- CurrentMatch: colUndefined,368- Spinner: colUndefined,369- Info: colUndefined,370- Cursor: colUndefined,371- Selected: colUndefined,372- Header: colUndefined,373- Border: colUndefined}407+ Colored: true,408+ Input: ColorAttr{colUndefined, AttrUndefined},409+ Fg: ColorAttr{colUndefined, AttrUndefined},410+ Bg: ColorAttr{colUndefined, AttrUndefined},411+ PreviewFg: ColorAttr{colUndefined, AttrUndefined},412+ PreviewBg: ColorAttr{colUndefined, AttrUndefined},413+ DarkBg: ColorAttr{colUndefined, AttrUndefined},414+ Gutter: ColorAttr{colUndefined, AttrUndefined},415+ Prompt: ColorAttr{colUndefined, AttrUndefined},416+ Match: ColorAttr{colUndefined, AttrUndefined},417+ Current: ColorAttr{colUndefined, AttrUndefined},418+ CurrentMatch: ColorAttr{colUndefined, AttrUndefined},419+ Spinner: ColorAttr{colUndefined, AttrUndefined},420+ Info: ColorAttr{colUndefined, AttrUndefined},421+ Cursor: ColorAttr{colUndefined, AttrUndefined},422+ Selected: ColorAttr{colUndefined, AttrUndefined},423+ Header: ColorAttr{colUndefined, AttrUndefined},424+ Border: ColorAttr{colUndefined, AttrUndefined}}425 }426 427+func NoColorTheme() *ColorTheme {428+ return &ColorTheme{429+ Colored: false,430+ Input: ColorAttr{colDefault, AttrRegular},431+ Fg: ColorAttr{colDefault, AttrRegular},432+ Bg: ColorAttr{colDefault, AttrRegular},433+ PreviewFg: ColorAttr{colDefault, AttrRegular},434+ PreviewBg: ColorAttr{colDefault, AttrRegular},435+ DarkBg: ColorAttr{colDefault, AttrRegular},436+ Gutter: ColorAttr{colDefault, AttrRegular},437+ Prompt: ColorAttr{colDefault, AttrRegular},438+ Match: ColorAttr{colDefault, Underline},439+ Current: ColorAttr{colDefault, Reverse},440+ CurrentMatch: ColorAttr{colDefault, Reverse | Underline},441+ Spinner: ColorAttr{colDefault, AttrRegular},442+ Info: ColorAttr{colDefault, AttrRegular},443+ Cursor: ColorAttr{colDefault, AttrRegular},444+ Selected: ColorAttr{colDefault, AttrRegular},445+ Header: ColorAttr{colDefault, AttrRegular},446+ Border: ColorAttr{colDefault, AttrRegular}}447+}448+449 func errorExit(message string) {450 fmt.Fprintln(os.Stderr, message)451 os.Exit(2)452 }453 454 func init() {455 Default16 = &ColorTheme{383- Fg: colDefault,384- Bg: colDefault,385- PreviewFg: colUndefined,386- PreviewBg: colUndefined,387- DarkBg: colBlack,388- Gutter: colUndefined,389- Prompt: colBlue,390- Match: colGreen,391- Current: colYellow,392- CurrentMatch: colGreen,393- Spinner: colGreen,394- Info: colWhite,395- Cursor: colRed,396- Selected: colMagenta,397- Header: colCyan,398- Border: colBlack}456+ Colored: true,457+ Input: ColorAttr{colDefault, AttrUndefined},458+ Fg: ColorAttr{colDefault, AttrUndefined},459+ Bg: ColorAttr{colDefault, AttrUndefined},460+ PreviewFg: ColorAttr{colUndefined, AttrUndefined},461+ PreviewBg: ColorAttr{colUndefined, AttrUndefined},462+ DarkBg: ColorAttr{colBlack, AttrUndefined},463+ Gutter: ColorAttr{colUndefined, AttrUndefined},464+ Prompt: ColorAttr{colBlue, AttrUndefined},465+ Match: ColorAttr{colGreen, AttrUndefined},466+ Current: ColorAttr{colYellow, AttrUndefined},467+ CurrentMatch: ColorAttr{colGreen, AttrUndefined},468+ Spinner: ColorAttr{colGreen, AttrUndefined},469+ Info: ColorAttr{colWhite, AttrUndefined},470+ Cursor: ColorAttr{colRed, AttrUndefined},471+ Selected: ColorAttr{colMagenta, AttrUndefined},472+ Header: ColorAttr{colCyan, AttrUndefined},473+ Border: ColorAttr{colBlack, AttrUndefined}}474 Dark256 = &ColorTheme{400- Fg: colDefault,401- Bg: colDefault,402- PreviewFg: colUndefined,403- PreviewBg: colUndefined,404- DarkBg: 236,405- Gutter: colUndefined,406- Prompt: 110,407- Match: 108,408- Current: 254,409- CurrentMatch: 151,410- Spinner: 148,411- Info: 144,412- Cursor: 161,413- Selected: 168,414- Header: 109,415- Border: 59}475+ Colored: true,476+ Input: ColorAttr{colDefault, AttrUndefined},477+ Fg: ColorAttr{colDefault, AttrUndefined},478+ Bg: ColorAttr{colDefault, AttrUndefined},479+ PreviewFg: ColorAttr{colUndefined, AttrUndefined},480+ PreviewBg: ColorAttr{colUndefined, AttrUndefined},481+ DarkBg: ColorAttr{236, AttrUndefined},482+ Gutter: ColorAttr{colUndefined, AttrUndefined},483+ Prompt: ColorAttr{110, AttrUndefined},484+ Match: ColorAttr{108, AttrUndefined},485+ Current: ColorAttr{254, AttrUndefined},486+ CurrentMatch: ColorAttr{151, AttrUndefined},487+ Spinner: ColorAttr{148, AttrUndefined},488+ Info: ColorAttr{144, AttrUndefined},489+ Cursor: ColorAttr{161, AttrUndefined},490+ Selected: ColorAttr{168, AttrUndefined},491+ Header: ColorAttr{109, AttrUndefined},492+ Border: ColorAttr{59, AttrUndefined}}493 Light256 = &ColorTheme{417- Fg: colDefault,418- Bg: colDefault,419- PreviewFg: colUndefined,420- PreviewBg: colUndefined,421- DarkBg: 251,422- Gutter: colUndefined,423- Prompt: 25,424- Match: 66,425- Current: 237,426- CurrentMatch: 23,427- Spinner: 65,428- Info: 101,429- Cursor: 161,430- Selected: 168,431- Header: 31,432- Border: 145}494+ Colored: true,495+ Input: ColorAttr{colDefault, AttrUndefined},496+ Fg: ColorAttr{colDefault, AttrUndefined},497+ Bg: ColorAttr{colDefault, AttrUndefined},498+ PreviewFg: ColorAttr{colUndefined, AttrUndefined},499+ PreviewBg: ColorAttr{colUndefined, AttrUndefined},500+ DarkBg: ColorAttr{251, AttrUndefined},501+ Gutter: ColorAttr{colUndefined, AttrUndefined},502+ Prompt: ColorAttr{25, AttrUndefined},503+ Match: ColorAttr{66, AttrUndefined},504+ Current: ColorAttr{237, AttrUndefined},505+ CurrentMatch: ColorAttr{23, AttrUndefined},506+ Spinner: ColorAttr{65, AttrUndefined},507+ Info: ColorAttr{101, AttrUndefined},508+ Cursor: ColorAttr{161, AttrUndefined},509+ Selected: ColorAttr{168, AttrUndefined},510+ Header: ColorAttr{31, AttrUndefined},511+ Border: ColorAttr{145, AttrUndefined}}512 }513 514 func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {436- if theme == nil {437- initPalette(theme)438- return439- }440-515 if forceBlack {442- theme.Bg = colBlack516+ theme.Bg = ColorAttr{colBlack, AttrUndefined}517 }518 445- o := func(a Color, b Color) Color {446- if b == colUndefined {447- return a519+ o := func(a ColorAttr, b ColorAttr) ColorAttr {520+ c := a521+ if b.Color != colUndefined {522+ c.Color = b.Color523 }524+ if b.Attr != AttrUndefined {525+ c.Attr = b.Attr526+ }449- return b527+ return c528 }529+ theme.Input = o(baseTheme.Input, theme.Input)530 theme.Fg = o(baseTheme.Fg, theme.Fg)531 theme.Bg = o(baseTheme.Bg, theme.Bg)532 theme.PreviewFg = o(theme.Fg, o(baseTheme.PreviewFg, theme.PreviewFg))533 theme.PreviewBg = o(theme.Bg, o(baseTheme.PreviewBg, theme.PreviewBg))13 unmodified lines547 initPalette(theme)548 }549 550 func initPalette(theme *ColorTheme) {472- idx := 0473- pair := func(fg, bg Color) ColorPair {474- idx++475- return ColorPair{fg, bg, idx}551+ pair := func(fg, bg ColorAttr) ColorPair {552+ return ColorPair{fg.Color, bg.Color, fg.Attr}553 }477- if theme != nil {478- ColPrompt = pair(theme.Prompt, theme.Bg)479- ColNormal = pair(theme.Fg, theme.Bg)480- ColMatch = pair(theme.Match, theme.Bg)481- ColCursor = pair(theme.Cursor, theme.Gutter)482- ColSelected = pair(theme.Selected, theme.Gutter)483- ColCurrent = pair(theme.Current, theme.DarkBg)484- ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)485- ColCurrentCursor = pair(theme.Cursor, theme.DarkBg)486- ColCurrentSelected = pair(theme.Selected, theme.DarkBg)487- ColSpinner = pair(theme.Spinner, theme.Bg)488- ColInfo = pair(theme.Info, theme.Bg)489- ColHeader = pair(theme.Header, theme.Bg)490- ColBorder = pair(theme.Border, theme.Bg)491- ColPreview = pair(theme.PreviewFg, theme.PreviewBg)492- ColPreviewBorder = pair(theme.Border, theme.PreviewBg)493- } else {494- ColPrompt = pair(colDefault, colDefault)495- ColNormal = pair(colDefault, colDefault)496- ColMatch = pair(colDefault, colDefault)497- ColCursor = pair(colDefault, colDefault)498- ColSelected = pair(colDefault, colDefault)499- ColCurrent = pair(colDefault, colDefault)500- ColCurrentMatch = pair(colDefault, colDefault)501- ColCurrentCursor = pair(colDefault, colDefault)502- ColCurrentSelected = pair(colDefault, colDefault)503- ColSpinner = pair(colDefault, colDefault)504- ColInfo = pair(colDefault, colDefault)505- ColHeader = pair(colDefault, colDefault)506- ColBorder = pair(colDefault, colDefault)507- ColPreview = pair(colDefault, colDefault)508- ColPreviewBorder = pair(colDefault, colDefault)509- }510-}554+ blank := theme.Fg555+ blank.Attr = AttrRegular556 512-func attrFor(color ColorPair, attr Attr) Attr {513- switch color {514- case ColCurrent:515- return attr | Reverse516- case ColMatch:517- return attr | Underline518- case ColCurrentMatch:519- return attr | Underline | Reverse520- }521- return attr557+ ColPrompt = pair(theme.Prompt, theme.Bg)558+ ColNormal = pair(theme.Fg, theme.Bg)559+ ColInput = pair(theme.Input, theme.Bg)560+ ColMatch = pair(theme.Match, theme.Bg)561+ ColCursor = pair(theme.Cursor, theme.Gutter)562+ ColCursorEmpty = pair(blank, theme.Gutter)563+ ColSelected = pair(theme.Selected, theme.Gutter)564+ ColCurrent = pair(theme.Current, theme.DarkBg)565+ ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)566+ ColCurrentCursor = pair(theme.Cursor, theme.DarkBg)567+ ColCurrentCursorEmpty = pair(blank, theme.DarkBg)568+ ColCurrentSelected = pair(theme.Selected, theme.DarkBg)569+ ColCurrentSelectedEmpty = pair(blank, theme.DarkBg)570+ ColSpinner = pair(theme.Spinner, theme.Bg)571+ ColInfo = pair(theme.Info, theme.Bg)572+ ColHeader = pair(theme.Header, theme.Bg)573+ ColBorder = pair(theme.Border, theme.Bg)574+ ColPreview = pair(theme.PreviewFg, theme.PreviewBg)575+ ColPreviewBorder = pair(theme.Border, theme.PreviewBg)576 }modified:src/core.go+2 added-2 removed
64 unmodified lines65 }66 67 var lineAnsiState, prevLineAnsiState *ansiState68 if opts.Ansi {69- if opts.Theme != nil {69+ if opts.Theme.Colored {70 ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {71 prevLineAnsiState = lineAnsiState72 trimmed, offsets, newState := extractColor(string(data), lineAnsiState, nil)73 lineAnsiState = newState27 unmodified lines101 })102 } else {103 chunkList = NewChunkList(func(item *Item, data []byte) bool {104 tokens := Tokenize(string(data), opts.Delimiter)105- if opts.Ansi && opts.Theme != nil && len(tokens) > 1 {105+ if opts.Ansi && opts.Theme.Colored && len(tokens) > 1 {106 var ansiState *ansiState107 if prevLineAnsiState != nil {108 ansiStateDup := *prevLineAnsiState109 ansiState = &ansiStateDup235 unmodified linesmodified:src/options_test.go+1 added-13 removed
293 unmodified lines294 t.Errorf("point should not be equivalent")295 }296 297 customized := parseTheme(theme, "fg:231,bg:232")298- if customized.Fg != 231 || customized.Bg != 232 {298+ if customized.Fg.Color != 231 || customized.Bg.Color != 232 {299 t.Errorf("color not customized")300 }301 if *tui.Dark256 == *customized {302 t.Errorf("colors should not be equivalent")9 unmodified lines312 t.Errorf("color not customized")313 }314 }315 316-func TestParseNilTheme(t *testing.T) {317- var theme *tui.ColorTheme318- newTheme := parseTheme(theme, "prompt:12")319- if newTheme != nil {320- t.Errorf("color is disabled. keep it that way.")321- }322- newTheme = parseTheme(theme, "prompt:12,dark,prompt:13")323- if newTheme.Prompt != 13 {324- t.Errorf("color should now be enabled and customized")325- }326-}327-316 func TestDefaultCtrlNP(t *testing.T) {317 check := func(words []string, key int, expected actionType) {318 opts := defaultOptions()319 parseOptions(opts, words)129 unmodified linesmodified:src/options.go+71 added-33 removed
588 unmodified lines589 return criteria590 }591 592 func dupeTheme(theme *tui.ColorTheme) *tui.ColorTheme {593- if theme != nil {594- dupe := *theme595- return &dupe593+ dupe := *theme594+ return &dupe596- }597- return nil595 }596 597 func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme {598 theme := dupeTheme(defaultTheme)16 unmodified lines615 if theme == nil {616 continue617 }618 622- pair := strings.Split(str, ":")623- if len(pair) != 2 {619+ components := strings.Split(str, ":")620+ if len(components) < 2 {621 fail()622 }623 624+ cattr := tui.NewColorAttr()625+ for _, component := range components[1:] {626+ switch component {627+ case "regular":628+ cattr.Attr = tui.AttrRegular629+ case "bold", "strong":630+ cattr.Attr |= tui.Bold631+ case "dim":632+ cattr.Attr |= tui.Dim633+ case "italic":634+ cattr.Attr |= tui.Italic635+ case "underline":636+ cattr.Attr |= tui.Underline637+ case "blink":638+ cattr.Attr |= tui.Blink639+ case "reverse":640+ cattr.Attr |= tui.Reverse641+ case "":627- var ansi tui.Color628- if rrggbb.MatchString(pair[1]) {629- ansi = tui.HexToColor(pair[1])630- } else {631- ansi32, err := strconv.Atoi(pair[1])632- if err != nil || ansi32 < -1 || ansi32 > 255 {633- fail()642+ default:643+ if rrggbb.MatchString(component) {644+ cattr.Color = tui.HexToColor(component)645+ } else {646+ ansi32, err := strconv.Atoi(component)647+ if err != nil || ansi32 < -1 || ansi32 > 255 {648+ fail()649+ }650+ cattr.Color = tui.Color(ansi32)651+ }652 }635- ansi = tui.Color(ansi32)653 }637- switch pair[0] {654+ switch components[0] {655+ case "input":656+ theme.Input = cattr657 case "fg":639- theme.Fg = ansi658+ theme.Fg = cattr659 case "bg":641- theme.Bg = ansi660+ theme.Bg = cattr661 case "preview-fg":643- theme.PreviewFg = ansi662+ theme.PreviewFg = cattr663 case "preview-bg":645- theme.PreviewBg = ansi664+ theme.PreviewBg = cattr665 case "fg+":647- theme.Current = ansi666+ theme.Current = cattr667 case "bg+":649- theme.DarkBg = ansi668+ theme.DarkBg = cattr669 case "gutter":651- theme.Gutter = ansi670+ theme.Gutter = cattr671 case "hl":653- theme.Match = ansi672+ theme.Match = cattr673 case "hl+":655- theme.CurrentMatch = ansi674+ theme.CurrentMatch = cattr675 case "border":657- theme.Border = ansi676+ theme.Border = cattr677 case "prompt":659- theme.Prompt = ansi678+ theme.Prompt = cattr679 case "spinner":661- theme.Spinner = ansi680+ theme.Spinner = cattr681 case "info":663- theme.Info = ansi682+ theme.Info = cattr683 case "pointer":665- theme.Cursor = ansi684+ theme.Cursor = cattr685 case "marker":667- theme.Selected = ansi686+ theme.Selected = cattr687 case "header":669- theme.Header = ansi688+ theme.Header = cattr689 default:690 fail()691 }692 }505 unmodified lines1198 opts.Ansi = false1199 case "--no-mouse":1200 opts.Mouse = false1201 case "+c", "--no-color":1183- opts.Theme = nil1202+ opts.Theme = tui.NoColorTheme()1203 case "+2", "--no-256":1204 opts.Theme = tui.Default161205 case "--black":1206 opts.Black = true289 unmodified lines1496 return1497 }1498 }1499 }1500+1501+ if opts.Bold {1502+ theme := opts.Theme1503+ boldify := func(c tui.ColorAttr) tui.ColorAttr {1504+ dup := c1505+ if !theme.Colored {1506+ dup.Attr |= tui.Bold1507+ } else if (c.Attr & tui.AttrRegular) == 0 {1508+ dup.Attr |= tui.Bold1509+ }1510+ return dup1511+ }1512+ theme.Current = boldify(theme.Current)1513+ theme.CurrentMatch = boldify(theme.CurrentMatch)1514+ theme.Prompt = boldify(theme.Prompt)1515+ theme.Input = boldify(theme.Input)1516+ theme.Cursor = boldify(theme.Cursor)1517+ theme.Spinner = boldify(theme.Spinner)1518+ }1519 }1520 1521 // ParseOptions parses command-line options1522 func ParseOptions() *Options {14 unmodified linesmodified:src/result_test.go+44 added-21 removed
103 unmodified lines104 // ------------ 20 ---- -- ----105 // ++++++++ ++++++++++106 // --++++++++-- --++++++++++---107 108- offsets := []Offset{Offset{5, 15}, Offset{25, 35}}108+ offsets := []Offset{{5, 15}, {25, 35}}109 item := Result{110 item: &Item{111 colors: &[]ansiOffset{112- ansiOffset{[2]int32{0, 20}, ansiState{1, 5, 0}},113- ansiOffset{[2]int32{22, 27}, ansiState{2, 6, tui.Bold}},114- ansiOffset{[2]int32{30, 32}, ansiState{3, 7, 0}},115- ansiOffset{[2]int32{33, 40}, ansiState{4, 8, tui.Bold}}}}}116- // [{[0 5] 9 false} {[5 15] 99 false} {[15 20] 9 false} {[22 25] 10 true} {[25 35] 99 false} {[35 40] 11 true}]112+ {[2]int32{0, 20}, ansiState{1, 5, 0}},113+ {[2]int32{22, 27}, ansiState{2, 6, tui.Bold}},114+ {[2]int32{30, 32}, ansiState{3, 7, 0}},115+ {[2]int32{33, 40}, ansiState{4, 8, tui.Bold}}}}}116 118- pair := tui.NewColorPair(99, 199)119- colors := item.colorOffsets(offsets, tui.Dark256, pair, tui.AttrRegular, true)120- assert := func(idx int, b int32, e int32, c tui.ColorPair, bold bool) {121- var attr tui.Attr122- if bold {123- attr = tui.Bold124- }117+ colBase := tui.NewColorPair(89, 189, tui.AttrUndefined)118+ colMatch := tui.NewColorPair(99, 199, tui.AttrUndefined)119+ colors := item.colorOffsets(offsets, tui.Dark256, colBase, colMatch, true)120+ assert := func(idx int, b int32, e int32, c tui.ColorPair) {121 o := colors[idx]126- if o.offset[0] != b || o.offset[1] != e || o.color != c || o.attr != attr {127- t.Error(o)122+ if o.offset[0] != b || o.offset[1] != e || o.color != c {123+ t.Error(o, b, e, c)124 }125 }130- assert(0, 0, 5, tui.NewColorPair(1, 5), false)131- assert(1, 5, 15, pair, false)132- assert(2, 15, 20, tui.NewColorPair(1, 5), false)133- assert(3, 22, 25, tui.NewColorPair(2, 6), true)134- assert(4, 25, 35, pair, false)135- assert(5, 35, 40, tui.NewColorPair(4, 8), true)126+ // [{[0 5] {1 5 0}} {[5 15] {99 199 0}} {[15 20] {1 5 0}}127+ // {[22 25] {2 6 1}} {[25 27] {99 199 1}} {[27 30] {99 199 0}}128+ // {[30 32] {99 199 0}} {[32 33] {99 199 0}} {[33 35] {99 199 1}}129+ // {[35 40] {4 8 1}}]130+ assert(0, 0, 5, tui.NewColorPair(1, 5, tui.AttrUndefined))131+ assert(1, 5, 15, colMatch)132+ assert(2, 15, 20, tui.NewColorPair(1, 5, tui.AttrUndefined))133+ assert(3, 22, 25, tui.NewColorPair(2, 6, tui.Bold))134+ assert(4, 25, 27, colMatch.WithAttr(tui.Bold))135+ assert(5, 27, 30, colMatch)136+ assert(6, 30, 32, colMatch)137+ assert(7, 32, 33, colMatch) // TODO: Should we merge consecutive blocks?138+ assert(8, 33, 35, colMatch.WithAttr(tui.Bold))139+ assert(9, 35, 40, tui.NewColorPair(4, 8, tui.Bold))140+141+ colRegular := tui.NewColorPair(-1, -1, tui.AttrUndefined)142+ colUnderline := tui.NewColorPair(-1, -1, tui.Underline)143+ colors = item.colorOffsets(offsets, tui.Dark256, colRegular, colUnderline, true)144+145+ // [{[0 5] {1 5 0}} {[5 15] {1 5 8}} {[15 20] {1 5 0}}146+ // {[22 25] {2 6 1}} {[25 27] {2 6 9}} {[27 30] {-1 -1 8}}147+ // {[30 32] {3 7 8}} {[32 33] {-1 -1 8}} {[33 35] {4 8 9}}148+ // {[35 40] {4 8 1}}]149+ assert(0, 0, 5, tui.NewColorPair(1, 5, tui.AttrUndefined))150+ assert(1, 5, 15, tui.NewColorPair(1, 5, tui.Underline))151+ assert(2, 15, 20, tui.NewColorPair(1, 5, tui.AttrUndefined))152+ assert(3, 22, 25, tui.NewColorPair(2, 6, tui.Bold))153+ assert(4, 25, 27, tui.NewColorPair(2, 6, tui.Bold|tui.Underline))154+ assert(5, 27, 30, colUnderline)155+ assert(6, 30, 32, tui.NewColorPair(3, 7, tui.Underline))156+ assert(7, 32, 33, colUnderline)157+ assert(8, 33, 35, tui.NewColorPair(4, 8, tui.Bold|tui.Underline))158+ assert(9, 35, 40, tui.NewColorPair(4, 8, tui.Bold))159 }modified:src/result.go+35 added-29 removed
13 unmodified lines14 15 type colorOffset struct {16 offset [2]int3217 color tui.ColorPair18- attr tui.Attr18 }19 20 type Result struct {21 item *Item63 unmodified lines85 func minRank() Result {86 return Result{item: &minItem, points: [4]uint16{math.MaxUint16, 0, 0, 0}}87 }88 90-func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme, color tui.ColorPair, attr tui.Attr, current bool) []colorOffset {89+func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme, colBase tui.ColorPair, colMatch tui.ColorPair, current bool) []colorOffset {90 itemColors := result.item.Colors()91 93- // No ANSI code, or --color=no92+ // No ANSI codes93 if len(itemColors) == 0 {94 var offsets []colorOffset95 for _, off := range matchOffsets {97- offsets = append(offsets, colorOffset{offset: [2]int32{off[0], off[1]}, color: color, attr: attr})96+ offsets = append(offsets, colorOffset{offset: [2]int32{off[0], off[1]}, color: colMatch})97 }98 return offsets99 }100 8 unmodified lines109 if ansi.offset[1] > maxCol {110 maxCol = ansi.offset[1]111 }112 }114- cols := make([]int, maxCol)113 114+ cols := make([]int, maxCol)115 for colorIndex, ansi := range itemColors {116 for i := ansi.offset[0]; i < ansi.offset[1]; i++ {118- cols[i] = colorIndex + 1 // XXX117+ cols[i] = colorIndex + 1 // 1-based index of itemColors118 }119 }120 121 for _, off := range matchOffsets {122 for i := off[0]; i < off[1]; i++ {124- cols[i] = -1123+ // Negative of 1-based index of itemColors124+ // - The extra -1 means highlighted125+ cols[i] = cols[i]*-1 - 1126 }127 }128 129 // sort.Sort(ByOrder(offsets))3 unmodified lines133 // ++++++++ ++++++++++134 // --++++++++-- --++++++++++---135 curr := 0136 start := 0137+ ansiToColorPair := func(ansi ansiOffset, base tui.ColorPair) tui.ColorPair {138+ fg := ansi.color.fg139+ bg := ansi.color.bg140+ if fg == -1 {141+ if current {142+ fg = theme.Current.Color143+ } else {144+ fg = theme.Fg.Color145+ }146+ }147+ if bg == -1 {148+ if current {149+ bg = theme.DarkBg.Color150+ } else {151+ bg = theme.Bg.Color152+ }153+ }154+ return tui.NewColorPair(fg, bg, ansi.color.attr).MergeAttr(base)155+ }156 var colors []colorOffset157 add := func(idx int) {158 if curr != 0 && idx > start {139- if curr == -1 {159+ if curr < 0 {160+ color := colMatch161+ if curr < -1 && theme.Colored {162+ origColor := ansiToColorPair(itemColors[-curr-2], colMatch)163+ color = origColor.MergeNonDefault(color)164+ }165 colors = append(colors, colorOffset{141- offset: [2]int32{int32(start), int32(idx)}, color: color, attr: attr})166+ offset: [2]int32{int32(start), int32(idx)}, color: color})167 } else {168 ansi := itemColors[curr-1]144- fg := ansi.color.fg145- bg := ansi.color.bg146- if theme != nil {147- if fg == -1 {148- if current {149- fg = theme.Current150- } else {151- fg = theme.Fg152- }153- }154- if bg == -1 {155- if current {156- bg = theme.DarkBg157- } else {158- bg = theme.Bg159- }160- }161- }169 colors = append(colors, colorOffset{170 offset: [2]int32{int32(start), int32(idx)},164- color: tui.NewColorPair(fg, bg),165- attr: ansi.color.attr.Merge(attr)})171+ color: ansiToColorPair(ansi, colBase)})172 }173 }174 }175 for idx, col := range cols {56 unmodified linesmodified:src/terminal.go+57 added-27 removed
21 unmodified lines22 // import "github.com/pkg/profile"23 24 var placeholder *regexp.Regexp25 var numericPrefix *regexp.Regexp26+var whiteSuffix *regexp.Regexp27 var activeTempFiles []string28 29 const ellipsis string = ".."30 const clearCode string = "\x1b[2J"31 32 func init() {33 placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`)34 numericPrefix = regexp.MustCompile(`^[[:punct:]]*([0-9]+)`)35+ whiteSuffix = regexp.MustCompile(`\s*$`)36 activeTempFiles = []string{}37 }38 39 type jumpMode int476 unmodified lines516 func (t *Terminal) parsePrompt(prompt string) (func(), int) {517 var state *ansiState518 trimmed, colors, _ := extractColor(prompt, state, nil)519 item := &Item{text: util.ToChars([]byte(trimmed)), colors: colors}520+521+ // "Prompt> "522+ // ------- // Do not apply ANSI attributes to the trailing whitespaces523+ // // unless the part has a non-default ANSI state524+ loc := whiteSuffix.FindStringIndex(trimmed)525+ if loc != nil {526+ blankState := ansiOffset{[2]int32{int32(loc[0]), int32(loc[1])}, ansiState{-1, -1, tui.AttrClear}}527+ if item.colors != nil {528+ lastColor := (*item.colors)[len(*item.colors)-1]529+ fmt.Println(lastColor.offset[1], int32(loc[1]))530+ if lastColor.offset[1] < int32(loc[1]) {531+ blankState.offset[0] = lastColor.offset[1]532+ colors := append(*item.colors, blankState)533+ item.colors = &colors534+ }535+ } else {536+ colors := []ansiOffset{blankState}537+ item.colors = &colors538+ }539+ }540 output := func() {541 t.printHighlighted(520- Result{item: item}, t.strong, tui.ColPrompt, tui.ColPrompt, false, false)542+ Result{item: item}, tui.ColPrompt, tui.ColPrompt, false, false)543 }544 _, promptLen := t.processTabs([]rune(trimmed), 0)545 546 return output, promptLen313 unmodified lines860 t.move(0, 0, true)861 t.prompt()862 863 before, after := t.updatePromptOffset()842- t.window.CPrint(tui.ColNormal, t.strong, string(before))843- t.window.CPrint(tui.ColNormal, t.strong, string(after))864+ t.window.CPrint(tui.ColInput, string(before))865+ t.window.CPrint(tui.ColInput, string(after))866 }867 868 func (t *Terminal) trimMessage(message string, maxWidth int) string {869 if len(message) <= maxWidth {10 unmodified lines880 t.move(1, 0, true)881 if t.reading {882 duration := int64(spinnerDuration)883 idx := (time.Now().UnixNano() % (duration * int64(len(t.spinner)))) / duration862- t.window.CPrint(tui.ColSpinner, t.strong, t.spinner[idx])884+ t.window.CPrint(tui.ColSpinner, t.spinner[idx])885 }886 t.move(1, 2, false)887 pos = 2888 case infoInline:2 unmodified lines891 return892 }893 t.move(0, pos, true)894 if t.reading {873- t.window.CPrint(tui.ColSpinner, t.strong, " < ")895+ t.window.CPrint(tui.ColSpinner, " < ")896 } else {875- t.window.CPrint(tui.ColPrompt, t.strong, " < ")897+ t.window.CPrint(tui.ColPrompt, " < ")898 }899 pos += len(" < ")900 case infoHidden:901 return22 unmodified lines924 if t.failed != nil && t.count == 0 {925 output = fmt.Sprintf("[Command failed: %s]", *t.failed)926 }927 output = t.trimMessage(output, t.window.Width()-pos)906- t.window.CPrint(tui.ColInfo, 0, output)928+ t.window.CPrint(tui.ColInfo, output)929 }930 931 func (t *Terminal) printHeader() {932 if len(t.header) == 0 {16 unmodified lines949 colors: colors}950 951 t.move(line, 2, true)952 t.printHighlighted(Result{item: item},931- tui.AttrRegular, tui.ColHeader, tui.ColHeader, false, false)953+ tui.ColHeader, tui.ColHeader, false, false)954 }955 }956 957 func (t *Terminal) printList() {21 unmodified lines979 980 func (t *Terminal) printItem(result Result, line int, i int, current bool) {981 item := result.item982 _, selected := t.selected[item.Index()]961- label := t.pointerEmpty983+ label := ""984 if t.jumping != jumpDisabled {985 if i < len(t.jumpLabels) {986 // Striped987 current = i%2 == 016 unmodified lines1004 }1005 1006 t.move(line, 0, false)1007 if current {1008+ if len(label) == 0 {1009+ t.window.CPrint(tui.ColCurrentCursorEmpty, t.pointerEmpty)1010+ } else {986- t.window.CPrint(tui.ColCurrentCursor, t.strong, label)1011+ t.window.CPrint(tui.ColCurrentCursor, label)1012+ }1013 if selected {988- t.window.CPrint(tui.ColCurrentSelected, t.strong, t.marker)1014+ t.window.CPrint(tui.ColCurrentSelected, t.marker)1015 } else {990- t.window.CPrint(tui.ColCurrentSelected, t.strong, t.markerEmpty)1016+ t.window.CPrint(tui.ColCurrentSelectedEmpty, t.markerEmpty)1017 }992- newLine.width = t.printHighlighted(result, t.strong, tui.ColCurrent, tui.ColCurrentMatch, true, true)1018+ newLine.width = t.printHighlighted(result, tui.ColCurrent, tui.ColCurrentMatch, true, true)1019 } else {1020+ if len(label) == 0 {1021+ t.window.CPrint(tui.ColCursorEmpty, t.pointerEmpty)1022+ } else {994- t.window.CPrint(tui.ColCursor, t.strong, label)1023+ t.window.CPrint(tui.ColCursor, label)1024+ }1025 if selected {996- t.window.CPrint(tui.ColSelected, t.strong, t.marker)1026+ t.window.CPrint(tui.ColSelected, t.marker)1027 } else {1028 t.window.Print(t.markerEmpty)1029 }1000- newLine.width = t.printHighlighted(result, 0, tui.ColNormal, tui.ColMatch, false, true)1030+ newLine.width = t.printHighlighted(result, tui.ColNormal, tui.ColMatch, false, true)1031 }1032 fillSpaces := prevLine.width - newLine.width1033 if fillSpaces > 0 {1034 t.window.Print(strings.Repeat(" ", fillSpaces))45 unmodified lines1080 func (t *Terminal) overflow(runes []rune, max int) bool {1081 return t.displayWidthWithLimit(runes, 0, max) > max1082 }1083 1054-func (t *Terminal) printHighlighted(result Result, attr tui.Attr, col1 tui.ColorPair, col2 tui.ColorPair, current bool, match bool) int {1084+func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMatch tui.ColorPair, current bool, match bool) int {1085 item := result.item1086 1087 // Overflow1088 text := make([]rune, item.text.Length())16 unmodified lines1105 for _, offset := range charOffsets {1106 maxe = util.Max(maxe, int(offset[1]))1107 }1108 1079- offsets := result.colorOffsets(charOffsets, t.theme, col2, attr, current)1109+ offsets := result.colorOffsets(charOffsets, t.theme, colBase, colMatch, current)1110 maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1)1111 maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))1112 displayWidth := t.displayWidthWithLimit(text, 0, maxWidth)1113 if displayWidth > maxWidth {49 unmodified lines1163 b := util.Constrain32(offset.offset[0], index, maxOffset)1164 e := util.Constrain32(offset.offset[1], index, maxOffset)1165 1166 substr, prefixWidth = t.processTabs(text[index:b], prefixWidth)1137- t.window.CPrint(col1, attr, substr)1167+ t.window.CPrint(colBase, substr)1168 1169 if b < e {1170 substr, prefixWidth = t.processTabs(text[b:e], prefixWidth)1141- t.window.CPrint(offset.color, offset.attr, substr)1171+ t.window.CPrint(offset.color, substr)1172 }1173 1174 index = e1175 if index >= maxOffset {1 unmodified line1177 }1178 }1179 if index < maxOffset {1180 substr, _ = t.processTabs(text[index:], prefixWidth)1151- t.window.CPrint(col1, attr, substr)1181+ t.window.CPrint(colBase, substr)1182 }1183 return displayWidth1184 }1185 4 unmodified lines1190 maxWidth := t.pwindow.Width()1191 if !t.previewer.scrollable {1192 if maxWidth > 0 {1193 t.pwindow.Move(0, maxWidth-1)1164- t.pwindow.CPrint(tui.ColSpinner, t.strong, spin)1194+ t.pwindow.CPrint(tui.ColSpinner, spin)1195 }1196 } else {1197 offsetString := fmt.Sprintf("%d/%d", t.previewer.offset+1, numLines)1198 if len(spin) > 0 {3 unmodified lines1202 offsetRunes, _ := t.trimRight([]rune(offsetString), maxWidth)1203 pos := maxWidth - t.displayWidth(offsetRunes)1204 t.pwindow.Move(0, pos)1205 if maxWidth > 0 {1176- t.pwindow.CPrint(tui.ColSpinner, t.strong, spin)1177- t.pwindow.CPrint(tui.ColInfo, tui.Reverse, string(offsetRunes))1206+ t.pwindow.CPrint(tui.ColSpinner, spin)1207+ t.pwindow.CPrint(tui.ColInfo.WithAttr(tui.Reverse), string(offsetRunes))1208 }1209 }1210 }1211 }2 unmodified lines1214 maxWidth := t.pwindow.Width()1215 lineNo := -t.previewer.offset1216 height := t.pwindow.Height()1217 if unchanged {1188- t.pwindow.Move(0, 0)1218+ t.pwindow.MoveAndClear(0, 0)1219 } else {1220 t.previewed.filled = false1221 t.pwindow.Erase()1222 }11 unmodified lines1234 trimmed, _ = t.trimRight(trimmed, maxWidth-t.pwindow.X())1235 }1236 str, width := t.processTabs(trimmed, prefixWidth)1237 prefixWidth += width1208- if t.theme != nil && ansi != nil && ansi.colored() {1238+ if t.theme.Colored && ansi != nil && ansi.colored() {1239 fillRet = t.pwindow.CFill(ansi.fg, ansi.bg, ansi.attr, str)1240 } else {1241 fillRet = t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, str)1242 }44 unmodified lines1287 1288 message := t.trimMessage("Loading ..", t.pwindow.Width())1289 pos := t.pwindow.Width() - len(message)1290 t.pwindow.Move(0, pos)1261- t.pwindow.CPrint(tui.ColInfo, tui.Reverse, message)1291+ t.pwindow.CPrint(tui.ColInfo.WithAttr(tui.Reverse), message)1292 }1293 1294 func (t *Terminal) processTabs(runes []rune, prefixWidth int) (string, int) {1295 var strbuf bytes.Buffer1257 unmodified linesmodified:CHANGELOG.md+7 added
13 unmodified lines14 echo "$i"15 sleep 0.0116 done'17 ```18+- Extended color specification: supports text styles19+ - `regular` / `bold` / `dim` / `underline` / `italic` / `reverse` / `blink`20+ ```sh21+ rg --line-number --no-heading --color=always "" |22+ fzf --ansi --prompt "Rg: " \23+ --color fg+:italic,hl:underline:-1,hl+:reverse:-1,prompt:reverse24+ ```25 - To indicate if `--multi` mode is enabled, fzf will print the number of26 selected items even when no item is selected27 ```sh28 seq 100 | fzf951 unmodified lines