Skip to content
Myr

Clean up renderer code

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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).

authored by Junegunn Choi · committed by Junegunn Choi · parent 7cfa6f0 · Browse files · 5 files+51 added−68 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+51 added−68 removed

  • other:+51 added−68 removed

5 files+51 added−68 removed

modified:src/tui/dummy.go-1 removed
31 unmodified lines
32func (r *FullscreenRenderer) Refresh() {}33func (r *FullscreenRenderer) Close() {}3435func (r *FullscreenRenderer) DoesAutoWrap() bool { return false }36func (r *FullscreenRenderer) IsOptimized() bool { return false }36func (r *FullscreenRenderer) GetChar() Event { return Event{} }37func (r *FullscreenRenderer) MaxX() int { return 0 }38func (r *FullscreenRenderer) MaxY() int { return 0 }39
5 unmodified lines
modified:src/tui/light.go-4 removed
618 unmodified lines
619func (r *LightRenderer) DoesAutoWrap() bool {620 return false621}622623func (r *LightRenderer) IsOptimized() bool {624 return false625}626623func (r *LightRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {624 w := &LightWindow{625 renderer: r,626 colored: r.theme != nil,
281 unmodified lines
modified:src/tui/tcell.go+15 added-14 removed
170 unmodified lines
171func (r *FullscreenRenderer) DoesAutoWrap() bool {172 return false173}174175func (r *FullscreenRenderer) IsOptimized() bool {176 return false177}178175func (r *FullscreenRenderer) Clear() {176 _screen.Sync()177 _screen.Clear()178}
225 unmodified lines
404405func fill(x, y, w, h int, r rune) {406 for ly := 0; ly <= h; ly++ {407 for lx := 0; lx <= w; lx++ {412 _screen.SetContent(x+lx, y+ly, r, nil, ColDefault.style())408 _screen.SetContent(x+lx, y+ly, r, nil, ColNormal.style())409 }410 }411}412413func (w *TcellWindow) Erase() {418 // TODO419 fill(w.left, w.top, w.width, w.height, ' ')414 fill(w.left-1, w.top, w.width+1, w.height, ' ')415}416417func (w *TcellWindow) Enclose(y int, x int) bool {418 return x >= w.left && x < (w.left+w.width) &&
8 unmodified lines
427428func (w *TcellWindow) MoveAndClear(y int, x int) {429 w.Move(y, x)430 for i := w.lastX; i < w.width; i++ {436 _screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, ColDefault.style())431 _screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, ColNormal.style())432 }433 w.lastX = x434}435436func (w *TcellWindow) Print(text string) {442 w.printString(text, ColDefault, 0)437 w.printString(text, ColNormal, 0)438}439440func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {441 t := text
4 unmodified lines
446 style = pair.style().447 Reverse(a&Attr(tcell.AttrReverse) != 0).448 Underline(a&Attr(tcell.AttrUnderline) != 0)449 } else {455 style = ColDefault.style().450 style = ColNormal.style().451 Reverse(a&Attr(tcell.AttrReverse) != 0 || pair == ColCurrent || pair == ColCurrentMatch).452 Underline(a&Attr(tcell.AttrUnderline) != 0 || pair == ColMatch || pair == ColCurrentMatch)453 }454 style = style.
42 unmodified lines
497 var style tcell.Style498 if w.color {499 style = pair.style()500 } else {506 style = ColDefault.style()501 style = ColNormal.style()502 }503 style = style.504 Blink(a&Attr(tcell.AttrBlink) != 0).505 Bold(a&Attr(tcell.AttrBold) != 0).
31 unmodified lines
537 return FillContinue538}539540func (w *TcellWindow) Fill(str string) FillReturn {546 return w.fillString(str, ColDefault, 0)541 return w.fillString(str, ColNormal, 0)542}543544func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {545 if fg == colDefault {546 fg = ColNormal.Fg()547 }548 if bg == colDefault {549 bg = ColNormal.Bg()550 }550 return w.fillString(str, ColorPair{fg, bg, -1}, a)551 return w.fillString(str, NewColorPair(fg, bg), a)552}553554func (w *TcellWindow) drawBorder(around bool) {555 left := w.left
4 unmodified lines
560 var style tcell.Style561 if w.color {562 style = ColBorder.style()563 } else {563 style = ColDefault.style()564 style = ColNormal.style()565 }566567 for x := left; x < right; x++ {568 _screen.SetContent(x, top, tcell.RuneHLine, nil, style)
15 unmodified lines
modified:src/tui/tui.go+29 added-37 removed
131 unmodified lines
132133type ColorPair struct {134 fg Color135 bg Color136 id int16136 id int137}138139func HexToColor(rrggbb string) Color {140 r, _ := strconv.ParseInt(rrggbb[1:3], 16, 0)
13 unmodified lines
154func (p ColorPair) Bg() Color {155 return p.bg156}157158func (p ColorPair) key() int {159 return (int(p.Fg()) << 8) + int(p.Bg())160}161158func (p ColorPair) is24() bool {163 return p.Fg().is24() || p.Bg().is24()159 return p.fg.is24() || p.bg.is24()160}161162type ColorTheme struct {163 Fg Color
10 unmodified lines
174 Header Color175 Border Color176}177182func (t *ColorTheme) HasBg() bool {183 return t.Bg != colDefault184}185178type Event struct {179 Type int180 Char rune181 MouseEvent *MouseEvent
29 unmodified lines
211212 MaxX() int213 MaxY() int214 DoesAutoWrap() bool223 IsOptimized() bool215216 NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window217}218
42 unmodified lines
261 Default16 *ColorTheme262 Dark256 *ColorTheme263 Light256 *ColorTheme264274 ColDefault ColorPair265 ColNormal ColorPair266 ColPrompt ColorPair267 ColMatch ColorPair268 ColCurrent ColorPair
3 unmodified lines
272 ColCursor ColorPair273 ColSelected ColorPair274 ColHeader ColorPair275 ColBorder ColorPair286 ColUser ColorPair276)277278func EmptyTheme() *ColorTheme {279 return &ColorTheme{
95 unmodified lines
375 initPalette(theme)376}377378func initPalette(theme *ColorTheme) {390 ColDefault = ColorPair{colDefault, colDefault, 0}379 idx := 0380 pair := func(fg, bg Color) ColorPair {381 idx++382 return ColorPair{fg, bg, idx}383 }384 if theme != nil {392 ColNormal = ColorPair{theme.Fg, theme.Bg, 1}393 ColPrompt = ColorPair{theme.Prompt, theme.Bg, 2}394 ColMatch = ColorPair{theme.Match, theme.Bg, 3}395 ColCurrent = ColorPair{theme.Current, theme.DarkBg, 4}396 ColCurrentMatch = ColorPair{theme.CurrentMatch, theme.DarkBg, 5}397 ColSpinner = ColorPair{theme.Spinner, theme.Bg, 6}398 ColInfo = ColorPair{theme.Info, theme.Bg, 7}399 ColCursor = ColorPair{theme.Cursor, theme.DarkBg, 8}400 ColSelected = ColorPair{theme.Selected, theme.DarkBg, 9}401 ColHeader = ColorPair{theme.Header, theme.Bg, 10}402 ColBorder = ColorPair{theme.Border, theme.Bg, 11}385 ColNormal = pair(theme.Fg, theme.Bg)386 ColPrompt = pair(theme.Prompt, theme.Bg)387 ColMatch = pair(theme.Match, theme.Bg)388 ColCurrent = pair(theme.Current, theme.DarkBg)389 ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)390 ColSpinner = pair(theme.Spinner, theme.Bg)391 ColInfo = pair(theme.Info, theme.Bg)392 ColCursor = pair(theme.Cursor, theme.DarkBg)393 ColSelected = pair(theme.Selected, theme.DarkBg)394 ColHeader = pair(theme.Header, theme.Bg)395 ColBorder = pair(theme.Border, theme.Bg)396 } else {404 ColNormal = ColorPair{colDefault, colDefault, 1}405 ColPrompt = ColorPair{colDefault, colDefault, 2}406 ColMatch = ColorPair{colDefault, colDefault, 3}407 ColCurrent = ColorPair{colDefault, colDefault, 4}408 ColCurrentMatch = ColorPair{colDefault, colDefault, 5}409 ColSpinner = ColorPair{colDefault, colDefault, 6}410 ColInfo = ColorPair{colDefault, colDefault, 7}411 ColCursor = ColorPair{colDefault, colDefault, 8}412 ColSelected = ColorPair{colDefault, colDefault, 9}413 ColHeader = ColorPair{colDefault, colDefault, 10}414 ColBorder = ColorPair{colDefault, colDefault, 11}397 ColNormal = pair(colDefault, colDefault)398 ColPrompt = pair(colDefault, colDefault)399 ColMatch = pair(colDefault, colDefault)400 ColCurrent = pair(colDefault, colDefault)401 ColCurrentMatch = pair(colDefault, colDefault)402 ColSpinner = pair(colDefault, colDefault)403 ColInfo = pair(colDefault, colDefault)404 ColCursor = pair(colDefault, colDefault)405 ColSelected = pair(colDefault, colDefault)406 ColHeader = pair(colDefault, colDefault)407 ColBorder = pair(colDefault, colDefault)408 }416 ColUser = ColorPair{colDefault, colDefault, 12}409}410411func attrFor(color ColorPair, attr Attr) Attr {412 switch color {
9 unmodified lines
modified:src/terminal.go+7 added-12 removed
621 unmodified lines
622 marginInt[3],623 width,624 height, tui.BorderNone)625 }626 if !t.tui.IsOptimized() {627 for i := 0; i < t.window.Height(); i++ {628 t.window.MoveAndClear(i, 0)626 for i := 0; i < t.window.Height(); i++ {627 t.window.MoveAndClear(i, 0)629 }628 }629 t.truncateQuery()630}631
87 unmodified lines
719 colors: colors}720721 t.move(line, 2, true)722 t.printHighlighted(Result{item: item},725 tui.AttrRegular, tui.ColHeader, tui.ColDefault, false, false)723 tui.AttrRegular, tui.ColHeader, tui.ColHeader, false, false)724 }725}726727func (t *Terminal) printList() {
44 unmodified lines
772 prevLine.result == newLine.result {773 return774 }775778 // Optimized renderer can simply erase to the end of the window779 t.move(line, 0, t.tui.IsOptimized())776 t.move(line, 0, false)777 t.window.CPrint(tui.ColCursor, t.strong, label)778 if current {779 if selected {780 t.window.CPrint(tui.ColSelected, t.strong, ">")
8 unmodified lines
789 t.window.Print(" ")790 }791 newLine.width = t.printHighlighted(result, 0, tui.ColNormal, tui.ColMatch, false, true)792 }796 if !t.tui.IsOptimized() {797 fillSpaces := prevLine.width - newLine.width798 if fillSpaces > 0 {799 t.window.Print(strings.Repeat(" ", fillSpaces))793 fillSpaces := prevLine.width - newLine.width794 if fillSpaces > 0 {795 t.window.Print(strings.Repeat(" ", fillSpaces))800 }796 }797 t.prevLines[i] = newLine798}799
1052 unmodified lines