summaryrefslogtreecommitdiff
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-05 23:02:52 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-05 23:02:52 +0900
commita5beb08ed72215e8b015851ad70bf3beca526429 (patch)
tree8b469e7210224defe03290878f5473f2cb8e3ce1 /src/tui
parent45fc7b903d1aab0871f03cbe1c4fbec71b932d9f (diff)
downloadfzf-a5beb08ed72215e8b015851ad70bf3beca526429.tar.gz
Border around the header section
Close #4159
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/light.go20
-rw-r--r--src/tui/tcell.go15
-rw-r--r--src/tui/tui.go38
3 files changed, 66 insertions, 7 deletions
diff --git a/src/tui/light.go b/src/tui/light.go
index 3cb1a8bc..48202bce 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -804,6 +804,9 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, wind
case WindowInput:
w.fg = r.theme.Input.Color
w.bg = r.theme.InputBg.Color
+ case WindowHeader:
+ w.fg = r.theme.Header.Color
+ w.bg = r.theme.HeaderBg.Color
case WindowPreview:
w.fg = r.theme.PreviewFg.Color
w.bg = r.theme.PreviewBg.Color
@@ -862,6 +865,8 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
color = ColListBorder
case WindowInput:
color = ColInputBorder
+ case WindowHeader:
+ color = ColHeaderBorder
case WindowPreview:
color = ColPreviewBorder
}
@@ -885,6 +890,8 @@ func (w *LightWindow) drawBorderVertical(left, right bool) {
color = ColListBorder
case WindowInput:
color = ColInputBorder
+ case WindowHeader:
+ color = ColHeaderBorder
case WindowPreview:
color = ColPreviewBorder
}
@@ -910,6 +917,8 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) {
color = ColListBorder
case WindowInput:
color = ColInputBorder
+ case WindowHeader:
+ color = ColHeaderBorder
case WindowPreview:
color = ColPreviewBorder
}
@@ -970,9 +979,16 @@ func (w *LightWindow) Y() int {
return w.posy
}
+func (w *LightWindow) EncloseX(x int) bool {
+ return x >= w.left && x < (w.left+w.width)
+}
+
+func (w *LightWindow) EncloseY(y int) bool {
+ return y >= w.top && y < (w.top+w.height)
+}
+
func (w *LightWindow) Enclose(y int, x int) bool {
- return x >= w.left && x < (w.left+w.width) &&
- y >= w.top && y < (w.top+w.height)
+ return w.EncloseX(x) && w.EncloseY(y)
}
func (w *LightWindow) Move(y int, x int) {
diff --git a/src/tui/tcell.go b/src/tui/tcell.go
index becdabcd..991052bd 100644
--- a/src/tui/tcell.go
+++ b/src/tui/tcell.go
@@ -557,6 +557,8 @@ func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int,
switch windowType {
case WindowList:
normal = ColListBorder
+ case WindowHeader:
+ normal = ColHeaderBorder
case WindowInput:
normal = ColInputBorder
case WindowPreview:
@@ -593,9 +595,16 @@ func (w *TcellWindow) EraseMaybe() bool {
return true
}
+func (w *TcellWindow) EncloseX(x int) bool {
+ return x >= w.left && x < (w.left+w.width)
+}
+
+func (w *TcellWindow) EncloseY(y int) bool {
+ return y >= w.top && y < (w.top+w.height)
+}
+
func (w *TcellWindow) Enclose(y int, x int) bool {
- return x >= w.left && x < (w.left+w.width) &&
- y >= w.top && y < (w.top+w.height)
+ return w.EncloseX(x) && w.EncloseY(y)
}
func (w *TcellWindow) Move(y int, x int) {
@@ -792,6 +801,8 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
style = ColBorder.style()
case WindowList:
style = ColListBorder.style()
+ case WindowHeader:
+ style = ColHeaderBorder.style()
case WindowInput:
style = ColInputBorder.style()
case WindowPreview:
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 832109ce..db846f75 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -324,6 +324,9 @@ type ColorTheme struct {
Cursor ColorAttr
Marker ColorAttr
Header ColorAttr
+ HeaderBg ColorAttr
+ HeaderBorder ColorAttr
+ HeaderLabel ColorAttr
Separator ColorAttr
Scrollbar ColorAttr
Border ColorAttr
@@ -543,6 +546,7 @@ const (
WindowList
WindowPreview
WindowInput
+ WindowHeader
)
type Renderer interface {
@@ -583,6 +587,8 @@ type Window interface {
X() int
Y() int
+ EncloseX(x int) bool
+ EncloseY(y int) bool
Enclose(y int, x int) bool
Move(y int, x int)
@@ -639,6 +645,8 @@ var (
ColSpinner ColorPair
ColInfo ColorPair
ColHeader ColorPair
+ ColHeaderBorder ColorPair
+ ColHeaderLabel ColorPair
ColSeparator ColorPair
ColScrollbar ColorPair
ColBorder ColorPair
@@ -691,6 +699,9 @@ func EmptyTheme() *ColorTheme {
InputBg: ColorAttr{colUndefined, AttrUndefined},
InputBorder: ColorAttr{colUndefined, AttrUndefined},
InputLabel: ColorAttr{colUndefined, AttrUndefined},
+ HeaderBg: ColorAttr{colUndefined, AttrUndefined},
+ HeaderBorder: ColorAttr{colUndefined, AttrUndefined},
+ HeaderLabel: ColorAttr{colUndefined, AttrUndefined},
}
}
@@ -731,6 +742,9 @@ func NoColorTheme() *ColorTheme {
InputBg: ColorAttr{colDefault, AttrUndefined},
InputBorder: ColorAttr{colDefault, AttrUndefined},
InputLabel: ColorAttr{colDefault, AttrUndefined},
+ HeaderBg: ColorAttr{colDefault, AttrUndefined},
+ HeaderBorder: ColorAttr{colDefault, AttrUndefined},
+ HeaderLabel: ColorAttr{colDefault, AttrUndefined},
}
}
@@ -845,10 +859,13 @@ func init() {
InputBg: ColorAttr{colUndefined, AttrUndefined},
InputBorder: ColorAttr{colUndefined, AttrUndefined},
InputLabel: ColorAttr{colUndefined, AttrUndefined},
+ HeaderBg: ColorAttr{colUndefined, AttrUndefined},
+ HeaderBorder: ColorAttr{colUndefined, AttrUndefined},
+ HeaderLabel: ColorAttr{colUndefined, AttrUndefined},
}
}
-func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
+func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool, hasInputWindow bool, hasHeaderWindow bool) {
if forceBlack {
theme.Bg = ColorAttr{colBlack, AttrUndefined}
}
@@ -896,9 +913,22 @@ func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
theme.Separator = o(theme.ListBorder, theme.Separator)
theme.Scrollbar = o(theme.ListBorder, theme.Scrollbar)
theme.PreviewScrollbar = o(theme.PreviewBorder, theme.PreviewScrollbar)
- theme.InputBg = o(theme.Bg, o(theme.ListBg, theme.InputBg))
+ if hasInputWindow {
+ theme.InputBg = o(theme.Bg, theme.InputBg)
+ } else {
+ // We shouldn't use input-bg if there's no separate input window
+ // e.g. fzf --color 'list-bg:green,input-bg:red' --no-input-border
+ theme.InputBg = o(theme.Bg, theme.ListBg)
+ }
theme.InputBorder = o(theme.Border, theme.InputBorder)
theme.InputLabel = o(theme.BorderLabel, theme.InputLabel)
+ if hasHeaderWindow {
+ theme.HeaderBg = o(theme.Bg, theme.HeaderBg)
+ } else {
+ theme.HeaderBg = o(theme.Bg, theme.ListBg)
+ }
+ theme.HeaderBorder = o(theme.Border, theme.HeaderBorder)
+ theme.HeaderLabel = o(theme.BorderLabel, theme.HeaderLabel)
initPalette(theme)
}
@@ -935,7 +965,6 @@ func initPalette(theme *ColorTheme) {
ColCurrentSelectedEmpty = pair(blank, theme.DarkBg)
ColSpinner = pair(theme.Spinner, theme.InputBg)
ColInfo = pair(theme.Info, theme.InputBg)
- ColHeader = pair(theme.Header, theme.ListBg)
ColSeparator = pair(theme.Separator, theme.InputBg)
ColScrollbar = pair(theme.Scrollbar, theme.ListBg)
ColBorder = pair(theme.Border, theme.Bg)
@@ -949,6 +978,9 @@ func initPalette(theme *ColorTheme) {
ColListBorder = pair(theme.ListBorder, theme.ListBg)
ColInputBorder = pair(theme.InputBorder, theme.InputBg)
ColInputLabel = pair(theme.InputLabel, theme.InputBg)
+ ColHeader = pair(theme.Header, theme.HeaderBg)
+ ColHeaderBorder = pair(theme.HeaderBorder, theme.HeaderBg)
+ ColHeaderLabel = pair(theme.HeaderLabel, theme.HeaderBg)
}
func runeWidth(r rune) int {