Add preview-fg and preview-bg for --color
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #1776
authored by Junegunn Choi · committed by Junegunn Choi · parent 8ae9677 · Browse files · 9 files·+96 added−51 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+96 added−51 removed
- other:+96 added−51 removed
Provenance
- Commit
3db6b88- Tree
7b0dc6f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
8ae9677
9 files changed+96 added−51 removed
modified:man/man1/fzf-tmux.1+1 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-tmux 1 "Nov 2019" "fzf 0.19.0" "fzf-tmux - open fzf in tmux split pane"24+.TH fzf-tmux 1 "Dec 2019" "fzf 0.20.0" "fzf-tmux - open fzf in tmux split pane"25 26 .SH NAME27 fzf-tmux - open fzf in tmux split pane28 26 unmodified linesmodified:man/man1/fzf.1+18 added-16 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 "Nov 2019" "fzf 0.19.0" "fzf - a command-line fuzzy finder"24+.TH fzf 1 "Dec 2019" "fzf 0.20.0" "fzf - a command-line fuzzy finder"25 26 .SH NAME27 fzf - a command-line fuzzy finder28 232 unmodified lines261 262 \fBdark \fRColor scheme for dark 256-color terminal263 \fBlight \fRColor scheme for light 256-color terminal264 \fB16 \fRColor scheme for 16-color terminal265- \fBbw \fRNo colors265+ \fBbw \fRNo colors (equivalent to \fB--no-color\fR)266 267 .B COLOR:268+ \fBfg \fRText269+ \fBbg \fRBackground268- \fBfg \fRText269- \fBbg \fRBackground270- \fBhl \fRHighlighted substrings271- \fBfg+ \fRText (current line)272- \fBbg+ \fRBackground (current line)273- \fBgutter \fRGutter on the left (defaults to \fBbg+\fR)274- \fBhl+ \fRHighlighted substrings (current line)275- \fBinfo \fRInfo276- \fBborder \fRBorder of the preview window and horizontal separators (\fB--border\fR)277- \fBprompt \fRPrompt278- \fBpointer \fRPointer to the current line279- \fBmarker \fRMulti-select marker280- \fBspinner \fRStreaming input indicator281- \fBheader \fRHeader270+ \fBpreview-fg \fRPreview window text271+ \fBpreview-bg \fRPreview window background272+ \fBhl \fRHighlighted substrings273+ \fBfg+ \fRText (current line)274+ \fBbg+ \fRBackground (current line)275+ \fBgutter \fRGutter on the left (defaults to \fBbg+\fR)276+ \fBhl+ \fRHighlighted substrings (current line)277+ \fBinfo \fRInfo278+ \fBborder \fRBorder of the preview window and horizontal separators (\fB--border\fR)279+ \fBprompt \fRPrompt280+ \fBpointer \fRPointer to the current line281+ \fBmarker \fRMulti-select marker282+ \fBspinner \fRStreaming input indicator283+ \fBheader \fRHeader284 285 .B EXAMPLES:286 287 \fB# Seoul256 theme with 8-bit colors483 unmodified linesmodified:src/tui/dummy.go+1 added-1 removed
37 unmodified lines38 func (r *FullscreenRenderer) MaxY() int { return 0 }39 40 func (r *FullscreenRenderer) RefreshWindows(windows []Window) {}41 42-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {42+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {43 return nil44 }modified:src/tui/light.go+13 added-8 removed
664 unmodified lines665 func (r *LightRenderer) DoesAutoWrap() bool {666 return false667 }668 669-func (r *LightRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {669+func (r *LightRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {670 w := &LightWindow{671 renderer: r,672 colored: r.theme != nil,673 border: borderStyle,4 unmodified lines678 tabstop: r.tabstop,679 fg: colDefault,680 bg: colDefault}681 if r.theme != nil {682+ if preview {683+ w.fg = r.theme.PreviewFg684+ w.bg = r.theme.PreviewBg685+ } else {682- w.fg = r.theme.Fg683- w.bg = r.theme.Bg686+ w.fg = r.theme.Fg687+ w.bg = r.theme.Bg688+ }689 }690 w.drawBorder()691 return w692 }15 unmodified lines708 }709 710 func (w *LightWindow) drawBorderAround() {711 w.Move(0, 0)707- w.CPrint(ColBorder, AttrRegular,712+ w.CPrint(ColPreviewBorder, AttrRegular,713 string(w.border.topLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.topRight))714 for y := 1; y < w.height-1; y++ {715 w.Move(y, 0)711- w.CPrint(ColBorder, AttrRegular, string(w.border.vertical))712- w.cprint2(colDefault, w.bg, AttrRegular, repeat(' ', w.width-2))713- w.CPrint(ColBorder, AttrRegular, string(w.border.vertical))716+ w.CPrint(ColPreviewBorder, AttrRegular, string(w.border.vertical))717+ w.CPrint(ColPreviewBorder, AttrRegular, repeat(' ', w.width-2))718+ w.CPrint(ColPreviewBorder, AttrRegular, string(w.border.vertical))719 }720 w.Move(w.height-1, 0)716- w.CPrint(ColBorder, AttrRegular,721+ w.CPrint(ColPreviewBorder, AttrRegular,722 string(w.border.bottomLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.bottomRight))723 }724 725 func (w *LightWindow) csi(code string) {231 unmodified linesmodified:src/tui/tcell.go+23 added-14 removed
30 unmodified lines31 top int32 left int33 width int34 height int35+ normal ColorPair36 lastX int37 lastY int38 moveCursor bool39 borderStyle BorderStyle368 unmodified lines408 }409 _screen.Show()410 }411 411-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {412- // TODO412+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {413+ normal := ColNormal414+ if preview {415+ normal = ColPreview416+ }417 return &TcellWindow{418 color: r.theme != nil,419 top: top,420 left: left,421 width: width,422 height: height,423+ normal: normal,424 borderStyle: borderStyle}425 }426 427 func (w *TcellWindow) Close() {428 // TODO429 }430 426-func fill(x, y, w, h int, r rune) {431+func fill(x, y, w, h int, n ColorPair, r rune) {432 for ly := 0; ly <= h; ly++ {433 for lx := 0; lx <= w; lx++ {429- _screen.SetContent(x+lx, y+ly, r, nil, ColNormal.style())434+ _screen.SetContent(x+lx, y+ly, r, nil, n.style())435 }436 }437 }438 439 func (w *TcellWindow) Erase() {435- fill(w.left-1, w.top, w.width+1, w.height, ' ')440+ fill(w.left-1, w.top, w.width+1, w.height, w.normal, ' ')441 }442 443 func (w *TcellWindow) Enclose(y int, x int) bool {444 return x >= w.left && x < (w.left+w.width) &&8 unmodified lines453 454 func (w *TcellWindow) MoveAndClear(y int, x int) {455 w.Move(y, x)456 for i := w.lastX; i < w.width; i++ {452- _screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, ColNormal.style())457+ _screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, w.normal.style())458 }459 w.lastX = x460 }461 462 func (w *TcellWindow) Print(text string) {458- w.printString(text, ColNormal, 0)463+ w.printString(text, w.normal, 0)464 }465 466 func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {467 t := text4 unmodified lines472 style = pair.style().473 Reverse(a&Attr(tcell.AttrReverse) != 0).474 Underline(a&Attr(tcell.AttrUnderline) != 0)475 } else {471- style = ColNormal.style().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)479 }480 style = style.42 unmodified lines523 var style tcell.Style524 if w.color {525 style = pair.style()526 } else {522- style = ColNormal.style()527+ style = w.normal.style()528 }529 style = style.530 Blink(a&Attr(tcell.AttrBlink) != 0).531 Bold(a&Attr(tcell.AttrBold) != 0).31 unmodified lines563 return FillContinue564 }565 566 func (w *TcellWindow) Fill(str string) FillReturn {562- return w.fillString(str, ColNormal, 0)567+ return w.fillString(str, w.normal, 0)568 }569 570 func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {571 if fg == colDefault {567- fg = ColNormal.Fg()572+ fg = w.normal.Fg()573 }574 if bg == colDefault {570- bg = ColNormal.Bg()575+ bg = w.normal.Bg()576 }577 return w.fillString(str, NewColorPair(fg, bg), a)578 }579 8 unmodified lines588 bot := top + w.height589 590 var style tcell.Style591 if w.color {592+ if w.borderStyle.shape == BorderAround {593+ style = ColPreviewBorder.style()594+ } else {587- style = ColBorder.style()595+ style = ColBorder.style()596+ }597 } else {589- style = ColNormal.style()598+ style = w.normal.style()599 }600 601 for x := left; x < right; x++ {602 _screen.SetContent(x, top, w.borderStyle.horizontal, nil, style)15 unmodified linesmodified:src/tui/tui.go+19 added-1 removed
171 unmodified lines172 173 type ColorTheme struct {174 Fg Color175 Bg Color176+ PreviewFg Color177+ PreviewBg Color178 DarkBg Color179 Gutter Color180 Prompt Color181 Match Color91 unmodified lines273 MaxX() int274 MaxY() int275 DoesAutoWrap() bool276 275- NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window277+ NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window278 }279 280 type Window interface {281 Top() int53 unmodified lines335 ColSpinner ColorPair336 ColInfo ColorPair337 ColHeader ColorPair338 ColBorder ColorPair339+ ColPreview ColorPair340+ ColPreviewBorder ColorPair341 )342 343 func EmptyTheme() *ColorTheme {344 return &ColorTheme{345 Fg: colUndefined,346 Bg: colUndefined,347+ PreviewFg: colUndefined,348+ PreviewBg: colUndefined,349 DarkBg: colUndefined,350 Gutter: colUndefined,351 Prompt: colUndefined,352 Match: colUndefined,15 unmodified lines368 func init() {369 Default16 = &ColorTheme{370 Fg: colDefault,371 Bg: colDefault,372+ PreviewFg: colUndefined,373+ PreviewBg: colUndefined,374 DarkBg: colBlack,375 Gutter: colUndefined,376 Prompt: colBlue,377 Match: colGreen,7 unmodified lines385 Border: colBlack}386 Dark256 = &ColorTheme{387 Fg: colDefault,388 Bg: colDefault,389+ PreviewFg: colUndefined,390+ PreviewBg: colUndefined,391 DarkBg: 236,392 Gutter: colUndefined,393 Prompt: 110,394 Match: 108,7 unmodified lines402 Border: 59}403 Light256 = &ColorTheme{404 Fg: colDefault,405 Bg: colDefault,406+ PreviewFg: colUndefined,407+ PreviewBg: colUndefined,408 DarkBg: 251,409 Gutter: colUndefined,410 Prompt: 25,411 Match: 66,24 unmodified lines436 return b437 }438 theme.Fg = o(baseTheme.Fg, theme.Fg)439 theme.Bg = o(baseTheme.Bg, theme.Bg)440+ theme.PreviewFg = o(theme.Fg, o(baseTheme.PreviewFg, theme.PreviewFg))441+ theme.PreviewBg = o(theme.Bg, o(baseTheme.PreviewBg, theme.PreviewBg))442 theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg)443 theme.Gutter = o(theme.DarkBg, o(baseTheme.Gutter, theme.Gutter))444 theme.Prompt = o(baseTheme.Prompt, theme.Prompt)445 theme.Match = o(baseTheme.Match, theme.Match)28 unmodified lines474 ColSpinner = pair(theme.Spinner, theme.Bg)475 ColInfo = pair(theme.Info, theme.Bg)476 ColHeader = pair(theme.Header, theme.Bg)477 ColBorder = pair(theme.Border, theme.Bg)478+ ColPreview = pair(theme.PreviewFg, theme.PreviewBg)479+ ColPreviewBorder = pair(theme.Border, theme.PreviewBg)480 } else {481 ColPrompt = pair(colDefault, colDefault)482 ColNormal = pair(colDefault, colDefault)483 ColMatch = pair(colDefault, colDefault)6 unmodified lines490 ColSpinner = pair(colDefault, colDefault)491 ColInfo = pair(colDefault, colDefault)492 ColHeader = pair(colDefault, colDefault)493 ColBorder = pair(colDefault, colDefault)494+ ColPreview = pair(colDefault, colDefault)495+ ColPreviewBorder = pair(colDefault, colDefault)496 }497 }498 499 func attrFor(color ColorPair, attr Attr) Attr {10 unmodified linesmodified:src/options.go+4 added
595 unmodified lines596 case "fg":597 theme.Fg = ansi598 case "bg":599 theme.Bg = ansi600+ case "preview-fg":601+ theme.PreviewFg = ansi602+ case "preview-bg":603+ theme.PreviewBg = ansi604 case "fg+":605 theme.Current = ansi606 case "bg+":607 theme.DarkBg = ansi783 unmodified linesmodified:src/terminal.go+10 added-9 removed
622 unmodified lines623 t.border = t.tui.NewWindow(624 marginInt[0]-1,625 marginInt[3],626 width,627+ height+2,627- height+2, tui.MakeBorderStyle(tui.BorderHorizontal, t.unicode))628+ false, tui.MakeBorderStyle(tui.BorderHorizontal, t.unicode))629 }630 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)631 if previewVisible {632 createPreviewWindow := func(y int, x int, w int, h int) {633 previewBorder := tui.MakeBorderStyle(tui.BorderAround, t.unicode)634 if !t.preview.border {635 previewBorder = tui.MakeTransparentBorder()636 }636- t.pborder = t.tui.NewWindow(y, x, w, h, previewBorder)637+ t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)638 pwidth := w - 4639 // ncurses auto-wraps the line when the cursor reaches the right-end of640 // the window. To prevent unintended line-wraps, we use the width one641 // column larger than the desired value.642 if !t.preview.wrap && t.tui.DoesAutoWrap() {643 pwidth += 1644 }644- t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, noBorder)645+ t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, true, noBorder)646 }647 switch t.preview.position {648 case posUp:649 pheight := calculateSize(height, t.preview.size, minHeight, 3)650 t.window = t.tui.NewWindow(650- marginInt[0]+pheight, marginInt[3], width, height-pheight, noBorder)651+ marginInt[0]+pheight, marginInt[3], width, height-pheight, false, noBorder)652 createPreviewWindow(marginInt[0], marginInt[3], width, pheight)653 case posDown:654 pheight := calculateSize(height, t.preview.size, minHeight, 3)655 t.window = t.tui.NewWindow(655- marginInt[0], marginInt[3], width, height-pheight, noBorder)656+ marginInt[0], marginInt[3], width, height-pheight, false, noBorder)657 createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)658 case posLeft:659 pwidth := calculateSize(width, t.preview.size, minWidth, 5)660 t.window = t.tui.NewWindow(660- marginInt[0], marginInt[3]+pwidth, width-pwidth, height, noBorder)661+ marginInt[0], marginInt[3]+pwidth, width-pwidth, height, false, noBorder)662 createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)663 case posRight:664 pwidth := calculateSize(width, t.preview.size, minWidth, 5)665 t.window = t.tui.NewWindow(665- marginInt[0], marginInt[3], width-pwidth, height, noBorder)666+ marginInt[0], marginInt[3], width-pwidth, height, false, noBorder)667 createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)668 }669 } else {670 t.window = t.tui.NewWindow(671 marginInt[0],672 marginInt[3],673 width,673- height, noBorder)674+ height, false, noBorder)675 }676 for i := 0; i < t.window.Height(); i++ {677 t.window.MoveAndClear(i, 0)678 }392 unmodified lines1071 prefixWidth += width1072 if t.theme != nil && ansi != nil && ansi.colored() {1073 fillRet = t.pwindow.CFill(ansi.fg, ansi.bg, ansi.attr, str)1074 } else {1074- fillRet = t.pwindow.CFill(tui.ColNormal.Fg(), tui.ColNormal.Bg(), tui.AttrRegular, str)1075+ fillRet = t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, str)1076 }1077 return fillRet == tui.FillContinue1078 })1079 t.previewer.more = t.previewer.more || t.pwindow.Y() == height-1 && t.pwindow.X() == t.pwindow.Width()1103 unmodified linesmodified:CHANGELOG.md+7 added-1 removed
1 CHANGELOG2 =========3 4-0.19.1 (WIP)4+0.20.0 (WIP)5 ------6+- Customizable preview window color (`preview-fg` and `preview-bg` for `--color`)7+ ```sh8+ fzf --preview 'cat {}' \9+ --color 'fg:#bbccdd,fg+:#ddeeff,bg:#334455,preview-bg:#223344,border:#778899' \10+ --border --height 20 --layout reverse --info inline11+ ```12 - Removed the immediate flicking of the screen on `reload` action.13 ```sh14 : | fzf --bind 'change:reload:seq {q}' --phony15 ```787 unmodified lines