Replace panic calls with logging in widgets

This commit is contained in:
Caleb Bassi 2019-01-25 20:04:34 -08:00
parent 6d3425b394
commit 78aed0d9bf
3 changed files with 17 additions and 9 deletions

View File

@ -97,7 +97,7 @@ func (self *LineGraph) Draw(buf *Buffer) {
}
if char != 10240 { // empty braille character
buf.SetCell(
Cell{char, NewStyle(colors[x][y])},
NewCell(char, NewStyle(colors[x][y])),
image.Pt(self.Inner.Min.X+x-1, self.Inner.Min.Y+y-1),
)
}
@ -120,7 +120,7 @@ func (self *LineGraph) Draw(buf *Buffer) {
for k, char := range str {
if char != ' ' {
buf.SetCell(
Cell{char, NewStyle(seriesLineColor)},
NewCell(char, NewStyle(seriesLineColor)),
image.Pt(self.Inner.Min.X+2+k, self.Inner.Min.Y+i+1),
)
}

View File

@ -2,6 +2,7 @@ package termui
import (
"image"
"log"
. "github.com/gizak/termui"
)
@ -84,12 +85,16 @@ func (self *Sparklines) Draw(buf *Buffer) {
percent := float64(curItem) / float64(max)
index := int(percent * 7)
if index < 0 || index >= len(BARS) {
panic("TODO")
log.Printf(
"invalid sparkline data value. index: %v, percent: %v, curItem: %v, offset: %v",
index, percent, curItem, offset,
)
continue
}
char = BARS[index]
}
buf.SetCell(
Cell{char, NewStyle(line.LineColor)},
NewCell(char, NewStyle(line.LineColor)),
image.Pt(self.Inner.Min.X+x-1, self.Inner.Min.Y+sparkY-1),
)
}

View File

@ -2,6 +2,7 @@ package termui
import (
"image"
"log"
"strings"
. "github.com/gizak/termui"
@ -77,11 +78,13 @@ func (self *Table) Draw(buf *Buffer) {
)
}
if self.TopRow < 0 {
log.Printf("table widget TopRow value less than 0. TopRow: %v", self.TopRow)
return
}
// prints each row
for rowNum := self.TopRow; rowNum < self.TopRow+self.Inner.Dy()-1 && rowNum < len(self.Rows); rowNum++ {
if rowNum < 0 || rowNum >= len(self.Rows) {
panic("TODO")
}
row := self.Rows[rowNum]
y := (rowNum + 2) - self.TopRow
@ -149,12 +152,12 @@ func (self *Table) calcPos() {
}
func (self *Table) Up() {
self.SelectedRow -= 1
self.SelectedRow--
self.calcPos()
}
func (self *Table) Down() {
self.SelectedRow += 1
self.SelectedRow++
self.calcPos()
}