m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 15:53:39 -05:00

Add preview-fg and preview-bg for --color

Close #1776
This commit is contained in:
Junegunn Choi
2019-12-12 23:03:17 +09:00
parent 8ae96774df
commit 3db6b88d82
9 changed files with 96 additions and 51 deletions

View File

@@ -32,6 +32,7 @@ type TcellWindow struct {
left int
width int
height int
normal ColorPair
lastX int
lastY int
moveCursor bool
@@ -408,14 +409,18 @@ 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}
}
@@ -423,16 +428,16 @@ 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 {
@@ -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) {
@@ -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)
}
@@ -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).
@@ -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)
}
@@ -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++ {