diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-02 16:24:46 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-02 16:25:00 +0900 |
| commit | ee3916be17a340205875f9ccfaf71a1683a2fdf9 (patch) | |
| tree | 0cc0e5d4d7067f0135f01431795a9f4541f7e532 /src/tui | |
| parent | fd513f8af8191cd60364497f4184b8accd988282 (diff) | |
| download | fzf-ee3916be17a340205875f9ccfaf71a1683a2fdf9.tar.gz | |
Border around the input section (prompt + info)
Close #4154
Diffstat (limited to 'src/tui')
| -rw-r--r-- | src/tui/light.go | 14 | ||||
| -rw-r--r-- | src/tui/tcell.go | 9 | ||||
| -rw-r--r-- | src/tui/tui.go | 36 |
3 files changed, 54 insertions, 5 deletions
diff --git a/src/tui/light.go b/src/tui/light.go index f0bb2fdf..3cb1a8bc 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -780,6 +780,8 @@ func (r *LightRenderer) MaxY() int { } func (r *LightRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window { + width = util.Max(0, width) + height = util.Max(0, height) w := &LightWindow{ renderer: r, colored: r.theme.Colored, @@ -799,6 +801,9 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, wind case WindowList: w.fg = r.theme.ListFg.Color w.bg = r.theme.ListBg.Color + case WindowInput: + w.fg = r.theme.Input.Color + w.bg = r.theme.InputBg.Color case WindowPreview: w.fg = r.theme.PreviewFg.Color w.bg = r.theme.PreviewBg.Color @@ -820,6 +825,9 @@ func (w *LightWindow) DrawHBorder() { } func (w *LightWindow) drawBorder(onlyHorizontal bool) { + if w.height == 0 { + return + } switch w.border.shape { case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble: w.drawBorderAround(onlyHorizontal) @@ -852,6 +860,8 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) { switch w.windowType { case WindowList: color = ColListBorder + case WindowInput: + color = ColInputBorder case WindowPreview: color = ColPreviewBorder } @@ -873,6 +883,8 @@ func (w *LightWindow) drawBorderVertical(left, right bool) { switch w.windowType { case WindowList: color = ColListBorder + case WindowInput: + color = ColInputBorder case WindowPreview: color = ColPreviewBorder } @@ -896,6 +908,8 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) { switch w.windowType { case WindowList: color = ColListBorder + case WindowInput: + color = ColInputBorder case WindowPreview: color = ColPreviewBorder } diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 92336cd0..becdabcd 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -551,10 +551,14 @@ func (r *FullscreenRenderer) RefreshWindows(windows []Window) { } func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window { + width = util.Max(0, width) + height = util.Max(0, height) normal := ColBorder switch windowType { case WindowList: normal = ColListBorder + case WindowInput: + normal = ColInputBorder case WindowPreview: normal = ColPreviewBorder } @@ -768,6 +772,9 @@ func (w *TcellWindow) DrawHBorder() { } func (w *TcellWindow) drawBorder(onlyHorizontal bool) { + if w.height == 0 { + return + } shape := w.borderStyle.shape if shape == BorderNone { return @@ -785,6 +792,8 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) { style = ColBorder.style() case WindowList: style = ColListBorder.style() + case WindowInput: + style = ColInputBorder.style() case WindowPreview: style = ColPreviewBorder.style() } diff --git a/src/tui/tui.go b/src/tui/tui.go index e2a891d0..832109ce 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -313,6 +313,9 @@ type ColorTheme struct { DarkBg ColorAttr Gutter ColorAttr Prompt ColorAttr + InputBg ColorAttr + InputBorder ColorAttr + InputLabel ColorAttr Match ColorAttr Current ColorAttr CurrentMatch ColorAttr @@ -539,6 +542,7 @@ const ( WindowBase WindowType = iota WindowList WindowPreview + WindowInput ) type Renderer interface { @@ -646,6 +650,8 @@ var ( ColPreviewSpinner ColorPair ColListBorder ColorPair ColListLabel ColorPair + ColInputBorder ColorPair + ColInputLabel ColorPair ) func EmptyTheme() *ColorTheme { @@ -682,6 +688,9 @@ func EmptyTheme() *ColorTheme { PreviewLabel: ColorAttr{colUndefined, AttrUndefined}, Separator: ColorAttr{colUndefined, AttrUndefined}, Scrollbar: ColorAttr{colUndefined, AttrUndefined}, + InputBg: ColorAttr{colUndefined, AttrUndefined}, + InputBorder: ColorAttr{colUndefined, AttrUndefined}, + InputLabel: ColorAttr{colUndefined, AttrUndefined}, } } @@ -719,6 +728,9 @@ func NoColorTheme() *ColorTheme { ListBorder: ColorAttr{colDefault, AttrUndefined}, Separator: ColorAttr{colDefault, AttrUndefined}, Scrollbar: ColorAttr{colDefault, AttrUndefined}, + InputBg: ColorAttr{colDefault, AttrUndefined}, + InputBorder: ColorAttr{colDefault, AttrUndefined}, + InputLabel: ColorAttr{colDefault, AttrUndefined}, } } @@ -756,6 +768,9 @@ func init() { ListBorder: ColorAttr{colUndefined, AttrUndefined}, Separator: ColorAttr{colUndefined, AttrUndefined}, Scrollbar: ColorAttr{colUndefined, AttrUndefined}, + InputBg: ColorAttr{colUndefined, AttrUndefined}, + InputBorder: ColorAttr{colUndefined, AttrUndefined}, + InputLabel: ColorAttr{colUndefined, AttrUndefined}, } Dark256 = &ColorTheme{ Colored: true, @@ -790,6 +805,9 @@ func init() { ListBorder: ColorAttr{colUndefined, AttrUndefined}, Separator: ColorAttr{colUndefined, AttrUndefined}, Scrollbar: ColorAttr{colUndefined, AttrUndefined}, + InputBg: ColorAttr{colUndefined, AttrUndefined}, + InputBorder: ColorAttr{colUndefined, AttrUndefined}, + InputLabel: ColorAttr{colUndefined, AttrUndefined}, } Light256 = &ColorTheme{ Colored: true, @@ -824,6 +842,9 @@ func init() { ListBorder: ColorAttr{colUndefined, AttrUndefined}, Separator: ColorAttr{colUndefined, AttrUndefined}, Scrollbar: ColorAttr{colUndefined, AttrUndefined}, + InputBg: ColorAttr{colUndefined, AttrUndefined}, + InputBorder: ColorAttr{colUndefined, AttrUndefined}, + InputLabel: ColorAttr{colUndefined, AttrUndefined}, } } @@ -875,6 +896,9 @@ 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)) + theme.InputBorder = o(theme.Border, theme.InputBorder) + theme.InputLabel = o(theme.BorderLabel, theme.InputLabel) initPalette(theme) } @@ -889,10 +913,10 @@ func initPalette(theme *ColorTheme) { blank := theme.ListFg blank.Attr = AttrRegular - ColPrompt = pair(theme.Prompt, theme.ListBg) + ColPrompt = pair(theme.Prompt, theme.InputBg) ColNormal = pair(theme.ListFg, theme.ListBg) ColSelected = pair(theme.SelectedFg, theme.SelectedBg) - ColInput = pair(theme.Input, theme.ListBg) + ColInput = pair(theme.Input, theme.InputBg) ColDisabled = pair(theme.Disabled, theme.ListBg) ColMatch = pair(theme.Match, theme.ListBg) ColSelectedMatch = pair(theme.SelectedMatch, theme.SelectedBg) @@ -909,10 +933,10 @@ func initPalette(theme *ColorTheme) { ColCurrentCursorEmpty = pair(blank, theme.DarkBg) ColCurrentMarker = pair(theme.Marker, theme.DarkBg) ColCurrentSelectedEmpty = pair(blank, theme.DarkBg) - ColSpinner = pair(theme.Spinner, theme.ListBg) - ColInfo = pair(theme.Info, theme.ListBg) + ColSpinner = pair(theme.Spinner, theme.InputBg) + ColInfo = pair(theme.Info, theme.InputBg) ColHeader = pair(theme.Header, theme.ListBg) - ColSeparator = pair(theme.Separator, theme.ListBg) + ColSeparator = pair(theme.Separator, theme.InputBg) ColScrollbar = pair(theme.Scrollbar, theme.ListBg) ColBorder = pair(theme.Border, theme.Bg) ColBorderLabel = pair(theme.BorderLabel, theme.Bg) @@ -923,6 +947,8 @@ func initPalette(theme *ColorTheme) { ColPreviewSpinner = pair(theme.Spinner, theme.PreviewBg) ColListLabel = pair(theme.ListLabel, theme.ListBg) ColListBorder = pair(theme.ListBorder, theme.ListBg) + ColInputBorder = pair(theme.InputBorder, theme.InputBg) + ColInputLabel = pair(theme.InputLabel, theme.InputBg) } func runeWidth(r rune) int { |
