Skip to content

Commit

Permalink
Add preview-fg and preview-bg for --color
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Dec 12, 2019
1 parent 8ae9677 commit 3db6b88
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 51 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
CHANGELOG
=========

0.19.1 (WIP)
0.20.0 (WIP)
------
- Customizable preview window color (`preview-fg` and `preview-bg` for `--color`)
```sh
fzf --preview 'cat {}' \
--color 'fg:#bbccdd,fg+:#ddeeff,bg:#334455,preview-bg:#223344,border:#778899' \
--border --height 20 --layout reverse --info inline
```
- Removed the immediate flicking of the screen on `reload` action.
```sh
: | fzf --bind 'change:reload:seq {q}' --phony
Expand Down
2 changes: 1 addition & 1 deletion man/man1/fzf-tmux.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
..
.TH fzf-tmux 1 "Nov 2019" "fzf 0.19.0" "fzf-tmux - open fzf in tmux split pane"
.TH fzf-tmux 1 "Dec 2019" "fzf 0.20.0" "fzf-tmux - open fzf in tmux split pane"

.SH NAME
fzf-tmux - open fzf in tmux split pane
Expand Down
34 changes: 18 additions & 16 deletions man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
..
.TH fzf 1 "Nov 2019" "fzf 0.19.0" "fzf - a command-line fuzzy finder"
.TH fzf 1 "Dec 2019" "fzf 0.20.0" "fzf - a command-line fuzzy finder"

.SH NAME
fzf - a command-line fuzzy finder
Expand Down Expand Up @@ -262,23 +262,25 @@ format.
\fBdark \fRColor scheme for dark 256-color terminal
\fBlight \fRColor scheme for light 256-color terminal
\fB16 \fRColor scheme for 16-color terminal
\fBbw \fRNo colors
\fBbw \fRNo colors (equivalent to \fB--no-color\fR)

.B COLOR:
\fBfg \fRText
\fBbg \fRBackground
\fBhl \fRHighlighted substrings
\fBfg+ \fRText (current line)
\fBbg+ \fRBackground (current line)
\fBgutter \fRGutter on the left (defaults to \fBbg+\fR)
\fBhl+ \fRHighlighted substrings (current line)
\fBinfo \fRInfo
\fBborder \fRBorder of the preview window and horizontal separators (\fB--border\fR)
\fBprompt \fRPrompt
\fBpointer \fRPointer to the current line
\fBmarker \fRMulti-select marker
\fBspinner \fRStreaming input indicator
\fBheader \fRHeader
\fBfg \fRText
\fBbg \fRBackground
\fBpreview-fg \fRPreview window text
\fBpreview-bg \fRPreview window background
\fBhl \fRHighlighted substrings
\fBfg+ \fRText (current line)
\fBbg+ \fRBackground (current line)
\fBgutter \fRGutter on the left (defaults to \fBbg+\fR)
\fBhl+ \fRHighlighted substrings (current line)
\fBinfo \fRInfo
\fBborder \fRBorder of the preview window and horizontal separators (\fB--border\fR)
\fBprompt \fRPrompt
\fBpointer \fRPointer to the current line
\fBmarker \fRMulti-select marker
\fBspinner \fRStreaming input indicator
\fBheader \fRHeader

.B EXAMPLES:

Expand Down
4 changes: 4 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme {
theme.Fg = ansi
case "bg":
theme.Bg = ansi
case "preview-fg":
theme.PreviewFg = ansi
case "preview-bg":
theme.PreviewBg = ansi
case "fg+":
theme.Current = ansi
case "bg+":
Expand Down
19 changes: 10 additions & 9 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ func (t *Terminal) resizeWindows() {
marginInt[0]-1,
marginInt[3],
width,
height+2, tui.MakeBorderStyle(tui.BorderHorizontal, t.unicode))
height+2,
false, tui.MakeBorderStyle(tui.BorderHorizontal, t.unicode))
}
noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)
if previewVisible {
Expand All @@ -633,44 +634,44 @@ func (t *Terminal) resizeWindows() {
if !t.preview.border {
previewBorder = tui.MakeTransparentBorder()
}
t.pborder = t.tui.NewWindow(y, x, w, h, previewBorder)
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)
pwidth := w - 4
// ncurses auto-wraps the line when the cursor reaches the right-end of
// the window. To prevent unintended line-wraps, we use the width one
// column larger than the desired value.
if !t.preview.wrap && t.tui.DoesAutoWrap() {
pwidth += 1
}
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, noBorder)
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, true, noBorder)
}
switch t.preview.position {
case posUp:
pheight := calculateSize(height, t.preview.size, minHeight, 3)
t.window = t.tui.NewWindow(
marginInt[0]+pheight, marginInt[3], width, height-pheight, noBorder)
marginInt[0]+pheight, marginInt[3], width, height-pheight, false, noBorder)
createPreviewWindow(marginInt[0], marginInt[3], width, pheight)
case posDown:
pheight := calculateSize(height, t.preview.size, minHeight, 3)
t.window = t.tui.NewWindow(
marginInt[0], marginInt[3], width, height-pheight, noBorder)
marginInt[0], marginInt[3], width, height-pheight, false, noBorder)
createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)
case posLeft:
pwidth := calculateSize(width, t.preview.size, minWidth, 5)
t.window = t.tui.NewWindow(
marginInt[0], marginInt[3]+pwidth, width-pwidth, height, noBorder)
marginInt[0], marginInt[3]+pwidth, width-pwidth, height, false, noBorder)
createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)
case posRight:
pwidth := calculateSize(width, t.preview.size, minWidth, 5)
t.window = t.tui.NewWindow(
marginInt[0], marginInt[3], width-pwidth, height, noBorder)
marginInt[0], marginInt[3], width-pwidth, height, false, noBorder)
createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)
}
} else {
t.window = t.tui.NewWindow(
marginInt[0],
marginInt[3],
width,
height, noBorder)
height, false, noBorder)
}
for i := 0; i < t.window.Height(); i++ {
t.window.MoveAndClear(i, 0)
Expand Down Expand Up @@ -1071,7 +1072,7 @@ func (t *Terminal) printPreview() {
if t.theme != nil && ansi != nil && ansi.colored() {
fillRet = t.pwindow.CFill(ansi.fg, ansi.bg, ansi.attr, str)
} else {
fillRet = t.pwindow.CFill(tui.ColNormal.Fg(), tui.ColNormal.Bg(), tui.AttrRegular, str)
fillRet = t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, str)
}
return fillRet == tui.FillContinue
})
Expand Down
2 changes: 1 addition & 1 deletion src/tui/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func (r *FullscreenRenderer) MaxY() int { return 0 }

func (r *FullscreenRenderer) RefreshWindows(windows []Window) {}

func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {
return nil
}
21 changes: 13 additions & 8 deletions src/tui/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ func (r *LightRenderer) DoesAutoWrap() bool {
return false
}

func (r *LightRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
func (r *LightRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {
w := &LightWindow{
renderer: r,
colored: r.theme != nil,
Expand All @@ -679,8 +679,13 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, bord
fg: colDefault,
bg: colDefault}
if r.theme != nil {
w.fg = r.theme.Fg
w.bg = r.theme.Bg
if preview {
w.fg = r.theme.PreviewFg
w.bg = r.theme.PreviewBg
} else {
w.fg = r.theme.Fg
w.bg = r.theme.Bg
}
}
w.drawBorder()
return w
Expand All @@ -704,16 +709,16 @@ func (w *LightWindow) drawBorderHorizontal() {

func (w *LightWindow) drawBorderAround() {
w.Move(0, 0)
w.CPrint(ColBorder, AttrRegular,
w.CPrint(ColPreviewBorder, AttrRegular,
string(w.border.topLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.topRight))
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
w.CPrint(ColBorder, AttrRegular, string(w.border.vertical))
w.cprint2(colDefault, w.bg, AttrRegular, repeat(' ', w.width-2))
w.CPrint(ColBorder, AttrRegular, string(w.border.vertical))
w.CPrint(ColPreviewBorder, AttrRegular, string(w.border.vertical))
w.CPrint(ColPreviewBorder, AttrRegular, repeat(' ', w.width-2))
w.CPrint(ColPreviewBorder, AttrRegular, string(w.border.vertical))
}
w.Move(w.height-1, 0)
w.CPrint(ColBorder, AttrRegular,
w.CPrint(ColPreviewBorder, AttrRegular,
string(w.border.bottomLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.bottomRight))
}

Expand Down
37 changes: 23 additions & 14 deletions src/tui/tcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type TcellWindow struct {
left int
width int
height int
normal ColorPair
lastX int
lastY int
moveCursor bool
Expand Down Expand Up @@ -408,31 +409,35 @@ func (r *FullscreenRenderer) RefreshWindows(windows []Window) {
_screen.Show()
}

func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
// TODO
func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {
normal := ColNormal
if preview {
normal = ColPreview
}
return &TcellWindow{
color: r.theme != nil,
top: top,
left: left,
width: width,
height: height,
normal: normal,
borderStyle: borderStyle}
}

func (w *TcellWindow) Close() {
// TODO
}

func fill(x, y, w, h int, r rune) {
func fill(x, y, w, h int, n ColorPair, r rune) {
for ly := 0; ly <= h; ly++ {
for lx := 0; lx <= w; lx++ {
_screen.SetContent(x+lx, y+ly, r, nil, ColNormal.style())
_screen.SetContent(x+lx, y+ly, r, nil, n.style())
}
}
}

func (w *TcellWindow) Erase() {
fill(w.left-1, w.top, w.width+1, w.height, ' ')
fill(w.left-1, w.top, w.width+1, w.height, w.normal, ' ')
}

func (w *TcellWindow) Enclose(y int, x int) bool {
Expand All @@ -449,13 +454,13 @@ func (w *TcellWindow) Move(y int, x int) {
func (w *TcellWindow) MoveAndClear(y int, x int) {
w.Move(y, x)
for i := w.lastX; i < w.width; i++ {
_screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, ColNormal.style())
_screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, w.normal.style())
}
w.lastX = x
}

func (w *TcellWindow) Print(text string) {
w.printString(text, ColNormal, 0)
w.printString(text, w.normal, 0)
}

func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {
Expand All @@ -468,7 +473,7 @@ func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {
Reverse(a&Attr(tcell.AttrReverse) != 0).
Underline(a&Attr(tcell.AttrUnderline) != 0)
} else {
style = ColNormal.style().
style = w.normal.style().
Reverse(a&Attr(tcell.AttrReverse) != 0 || pair == ColCurrent || pair == ColCurrentMatch).
Underline(a&Attr(tcell.AttrUnderline) != 0 || pair == ColMatch || pair == ColCurrentMatch)
}
Expand Down Expand Up @@ -519,7 +524,7 @@ func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn
if w.color {
style = pair.style()
} else {
style = ColNormal.style()
style = w.normal.style()
}
style = style.
Blink(a&Attr(tcell.AttrBlink) != 0).
Expand Down Expand Up @@ -559,15 +564,15 @@ func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn
}

func (w *TcellWindow) Fill(str string) FillReturn {
return w.fillString(str, ColNormal, 0)
return w.fillString(str, w.normal, 0)
}

func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
if fg == colDefault {
fg = ColNormal.Fg()
fg = w.normal.Fg()
}
if bg == colDefault {
bg = ColNormal.Bg()
bg = w.normal.Bg()
}
return w.fillString(str, NewColorPair(fg, bg), a)
}
Expand All @@ -584,9 +589,13 @@ func (w *TcellWindow) drawBorder() {

var style tcell.Style
if w.color {
style = ColBorder.style()
if w.borderStyle.shape == BorderAround {
style = ColPreviewBorder.style()
} else {
style = ColBorder.style()
}
} else {
style = ColNormal.style()
style = w.normal.style()
}

for x := left; x < right; x++ {
Expand Down
Loading

0 comments on commit 3db6b88

Please sign in to comment.