From 9a2b7f559c88067c25a65a6a34c8e172bdf830dc Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 31 Dec 2024 17:03:18 +0900 Subject: Add --list-border for additional border around the list section Close #4148 --- src/tui/tcell.go | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'src/tui/tcell.go') diff --git a/src/tui/tcell.go b/src/tui/tcell.go index a3ce2cb1..92336cd0 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -40,7 +40,7 @@ type Attr int32 type TcellWindow struct { color bool - preview bool + windowType WindowType top int left int width int @@ -106,8 +106,12 @@ func (r *FullscreenRenderer) PassThrough(str string) { func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {} -func (r *FullscreenRenderer) defaultTheme() *ColorTheme { - if _screen.Colors() >= 256 { +func (r *FullscreenRenderer) DefaultTheme() *ColorTheme { + s, e := r.getScreen() + if e != nil { + return Default16 + } + if s.Colors() >= 256 { return Dark256 } return Default16 @@ -148,8 +152,19 @@ var ( _initialResize bool = true ) +func (r *FullscreenRenderer) getScreen() (tcell.Screen, error) { + if _screen == nil { + s, e := tcell.NewScreen() + if e != nil { + return nil, e + } + _screen = s + } + return _screen, nil +} + func (r *FullscreenRenderer) initScreen() error { - s, e := tcell.NewScreen() + s, e := r.getScreen() if e != nil { return e } @@ -161,7 +176,6 @@ func (r *FullscreenRenderer) initScreen() error { } else { s.DisableMouse() } - _screen = s return nil } @@ -174,7 +188,6 @@ func (r *FullscreenRenderer) Init() error { if err := r.initScreen(); err != nil { return err } - initTheme(r.theme, r.defaultTheme(), r.forceBlack) return nil } @@ -537,14 +550,17 @@ func (r *FullscreenRenderer) RefreshWindows(windows []Window) { _screen.Show() } -func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window { - normal := ColNormal - if preview { - normal = ColPreview +func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, windowType WindowType, borderStyle BorderStyle, erase bool) Window { + normal := ColBorder + switch windowType { + case WindowList: + normal = ColListBorder + case WindowPreview: + normal = ColPreviewBorder } w := &TcellWindow{ color: r.theme.Colored, - preview: preview, + windowType: windowType, top: top, left: left, width: width, @@ -564,11 +580,7 @@ func fill(x, y, w, h int, n ColorPair, r rune) { } func (w *TcellWindow) Erase() { - if w.borderStyle.shape.HasLeft() { - fill(w.left-1, w.top, w.width, w.height-1, w.normal, ' ') - } else { - fill(w.left, w.top, w.width-1, w.height-1, w.normal, ' ') - } + fill(w.left, w.top, w.width-1, w.height-1, w.normal, ' ') w.drawBorder(false) } @@ -768,10 +780,13 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) { var style tcell.Style if w.color { - if w.preview { - style = ColPreviewBorder.style() - } else { + switch w.windowType { + case WindowBase: style = ColBorder.style() + case WindowList: + style = ColListBorder.style() + case WindowPreview: + style = ColPreviewBorder.style() } } else { style = w.normal.style() -- cgit v1.2.3