summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-09-09 13:50:07 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-09-09 23:20:42 +0900
commite1582b8323a70785d7ebefce993df7474a28e749 (patch)
tree6ece7921cbada4dd247e8a73d8bfee2eac752a68 /src/tui
parent7cfa6f0265a7a786b931dde03b75843124a984b2 (diff)
Clean up renderer code
Remove code that is no longer relevant after the removal of ncurses renderer. This commit also fixes background color issue on tcell-based FullscreenRenderer (Windows).
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/dummy.go1
-rw-r--r--src/tui/light.go4
-rw-r--r--src/tui/tcell.go29
-rw-r--r--src/tui/tui.go66
4 files changed, 44 insertions, 56 deletions
diff --git a/src/tui/dummy.go b/src/tui/dummy.go
index c96ce8eb..3965c9ea 100644
--- a/src/tui/dummy.go
+++ b/src/tui/dummy.go
@@ -33,7 +33,6 @@ func (r *FullscreenRenderer) Refresh() {}
func (r *FullscreenRenderer) Close() {}
func (r *FullscreenRenderer) DoesAutoWrap() bool { return false }
-func (r *FullscreenRenderer) IsOptimized() bool { return false }
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
func (r *FullscreenRenderer) MaxX() int { return 0 }
func (r *FullscreenRenderer) MaxY() int { return 0 }
diff --git a/src/tui/light.go b/src/tui/light.go
index fe9035ea..52e26edb 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -620,10 +620,6 @@ func (r *LightRenderer) DoesAutoWrap() bool {
return false
}
-func (r *LightRenderer) IsOptimized() bool {
- return false
-}
-
func (r *LightRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
w := &LightWindow{
renderer: r,
diff --git a/src/tui/tcell.go b/src/tui/tcell.go
index bed52801..7db37c4c 100644
--- a/src/tui/tcell.go
+++ b/src/tui/tcell.go
@@ -172,10 +172,6 @@ func (r *FullscreenRenderer) DoesAutoWrap() bool {
return false
}
-func (r *FullscreenRenderer) IsOptimized() bool {
- return false
-}
-
func (r *FullscreenRenderer) Clear() {
_screen.Sync()
_screen.Clear()
@@ -409,14 +405,13 @@ func (w *TcellWindow) Close() {
func fill(x, y, w, h int, r rune) {
for ly := 0; ly <= h; ly++ {
for lx := 0; lx <= w; lx++ {
- _screen.SetContent(x+lx, y+ly, r, nil, ColDefault.style())
+ _screen.SetContent(x+lx, y+ly, r, nil, ColNormal.style())
}
}
}
func (w *TcellWindow) Erase() {
- // TODO
- fill(w.left, w.top, w.width, w.height, ' ')
+ fill(w.left-1, w.top, w.width+1, w.height, ' ')
}
func (w *TcellWindow) Enclose(y int, x int) bool {
@@ -433,13 +428,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, ColDefault.style())
+ _screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, ColNormal.style())
}
w.lastX = x
}
func (w *TcellWindow) Print(text string) {
- w.printString(text, ColDefault, 0)
+ w.printString(text, ColNormal, 0)
}
func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {
@@ -452,7 +447,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 = ColDefault.style().
+ style = ColNormal.style().
Reverse(a&Attr(tcell.AttrReverse) != 0 || pair == ColCurrent || pair == ColCurrentMatch).
Underline(a&Attr(tcell.AttrUnderline) != 0 || pair == ColMatch || pair == ColCurrentMatch)
}
@@ -503,7 +498,7 @@ func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn
if w.color {
style = pair.style()
} else {
- style = ColDefault.style()
+ style = ColNormal.style()
}
style = style.
Blink(a&Attr(tcell.AttrBlink) != 0).
@@ -543,11 +538,17 @@ func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn
}
func (w *TcellWindow) Fill(str string) FillReturn {
- return w.fillString(str, ColDefault, 0)
+ return w.fillString(str, ColNormal, 0)
}
func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
- return w.fillString(str, ColorPair{fg, bg, -1}, a)
+ if fg == colDefault {
+ fg = ColNormal.Fg()
+ }
+ if bg == colDefault {
+ bg = ColNormal.Bg()
+ }
+ return w.fillString(str, NewColorPair(fg, bg), a)
}
func (w *TcellWindow) drawBorder(around bool) {
@@ -560,7 +561,7 @@ func (w *TcellWindow) drawBorder(around bool) {
if w.color {
style = ColBorder.style()
} else {
- style = ColDefault.style()
+ style = ColNormal.style()
}
for x := left; x < right; x++ {
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 24206160..244e0b05 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -133,7 +133,7 @@ const (
type ColorPair struct {
fg Color
bg Color
- id int16
+ id int
}
func HexToColor(rrggbb string) Color {
@@ -155,12 +155,8 @@ func (p ColorPair) Bg() Color {
return p.bg
}
-func (p ColorPair) key() int {
- return (int(p.Fg()) << 8) + int(p.Bg())
-}
-
func (p ColorPair) is24() bool {
- return p.Fg().is24() || p.Bg().is24()
+ return p.fg.is24() || p.bg.is24()
}
type ColorTheme struct {
@@ -179,10 +175,6 @@ type ColorTheme struct {
Border Color
}
-func (t *ColorTheme) HasBg() bool {
- return t.Bg != colDefault
-}
-
type Event struct {
Type int
Char rune
@@ -220,7 +212,6 @@ type Renderer interface {
MaxX() int
MaxY() int
DoesAutoWrap() bool
- IsOptimized() bool
NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window
}
@@ -271,7 +262,6 @@ var (
Dark256 *ColorTheme
Light256 *ColorTheme
- ColDefault ColorPair
ColNormal ColorPair
ColPrompt ColorPair
ColMatch ColorPair
@@ -283,7 +273,6 @@ var (
ColSelected ColorPair
ColHeader ColorPair
ColBorder ColorPair
- ColUser ColorPair
)
func EmptyTheme() *ColorTheme {
@@ -387,33 +376,36 @@ func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
}
func initPalette(theme *ColorTheme) {
- ColDefault = ColorPair{colDefault, colDefault, 0}
+ idx := 0
+ pair := func(fg, bg Color) ColorPair {
+ idx++
+ return ColorPair{fg, bg, idx}
+ }
if theme != nil {
- ColNormal = ColorPair{theme.Fg, theme.Bg, 1}
- ColPrompt = ColorPair{theme.Prompt, theme.Bg, 2}
- ColMatch = ColorPair{theme.Match, theme.Bg, 3}
- ColCurrent = ColorPair{theme.Current, theme.DarkBg, 4}
- ColCurrentMatch = ColorPair{theme.CurrentMatch, theme.DarkBg, 5}
- ColSpinner = ColorPair{theme.Spinner, theme.Bg, 6}
- ColInfo = ColorPair{theme.Info, theme.Bg, 7}
- ColCursor = ColorPair{theme.Cursor, theme.DarkBg, 8}
- ColSelected = ColorPair{theme.Selected, theme.DarkBg, 9}
- ColHeader = ColorPair{theme.Header, theme.Bg, 10}
- ColBorder = ColorPair{theme.Border, theme.Bg, 11}
+ ColNormal = pair(theme.Fg, theme.Bg)
+ ColPrompt = pair(theme.Prompt, theme.Bg)
+ ColMatch = pair(theme.Match, theme.Bg)
+ ColCurrent = pair(theme.Current, theme.DarkBg)
+ ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)
+ ColSpinner = pair(theme.Spinner, theme.Bg)
+ ColInfo = pair(theme.Info, theme.Bg)
+ ColCursor = pair(theme.Cursor, theme.DarkBg)
+ ColSelected = pair(theme.Selected, theme.DarkBg)
+ ColHeader = pair(theme.Header, theme.Bg)
+ ColBorder = pair(theme.Border, theme.Bg)
} else {
- ColNormal = ColorPair{colDefault, colDefault, 1}
- ColPrompt = ColorPair{colDefault, colDefault, 2}
- ColMatch = ColorPair{colDefault, colDefault, 3}
- ColCurrent = ColorPair{colDefault, colDefault, 4}
- ColCurrentMatch = ColorPair{colDefault, colDefault, 5}
- ColSpinner = ColorPair{colDefault, colDefault, 6}
- ColInfo = ColorPair{colDefault, colDefault, 7}
- ColCursor = ColorPair{colDefault, colDefault, 8}
- ColSelected = ColorPair{colDefault, colDefault, 9}
- ColHeader = ColorPair{colDefault, colDefault, 10}
- ColBorder = ColorPair{colDefault, colDefault, 11}
+ ColNormal = pair(colDefault, colDefault)
+ ColPrompt = pair(colDefault, colDefault)
+ ColMatch = pair(colDefault, colDefault)
+ ColCurrent = pair(colDefault, colDefault)
+ ColCurrentMatch = pair(colDefault, colDefault)
+ ColSpinner = pair(colDefault, colDefault)
+ ColInfo = pair(colDefault, colDefault)
+ ColCursor = pair(colDefault, colDefault)
+ ColSelected = pair(colDefault, colDefault)
+ ColHeader = pair(colDefault, colDefault)
+ ColBorder = pair(colDefault, colDefault)
}
- ColUser = ColorPair{colDefault, colDefault, 12}
}
func attrFor(color ColorPair, attr Attr) Attr {