Replace panic calls with logging in widgets
This commit is contained in:
parent
6d3425b394
commit
78aed0d9bf
|
@ -97,7 +97,7 @@ func (self *LineGraph) Draw(buf *Buffer) {
|
||||||
}
|
}
|
||||||
if char != 10240 { // empty braille character
|
if char != 10240 { // empty braille character
|
||||||
buf.SetCell(
|
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),
|
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 {
|
for k, char := range str {
|
||||||
if char != ' ' {
|
if char != ' ' {
|
||||||
buf.SetCell(
|
buf.SetCell(
|
||||||
Cell{char, NewStyle(seriesLineColor)},
|
NewCell(char, NewStyle(seriesLineColor)),
|
||||||
image.Pt(self.Inner.Min.X+2+k, self.Inner.Min.Y+i+1),
|
image.Pt(self.Inner.Min.X+2+k, self.Inner.Min.Y+i+1),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package termui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
"log"
|
||||||
|
|
||||||
. "github.com/gizak/termui"
|
. "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
@ -84,12 +85,16 @@ func (self *Sparklines) Draw(buf *Buffer) {
|
||||||
percent := float64(curItem) / float64(max)
|
percent := float64(curItem) / float64(max)
|
||||||
index := int(percent * 7)
|
index := int(percent * 7)
|
||||||
if index < 0 || index >= len(BARS) {
|
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]
|
char = BARS[index]
|
||||||
}
|
}
|
||||||
buf.SetCell(
|
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),
|
image.Pt(self.Inner.Min.X+x-1, self.Inner.Min.Y+sparkY-1),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package termui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
. "github.com/gizak/termui"
|
. "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
|
// prints each row
|
||||||
for rowNum := self.TopRow; rowNum < self.TopRow+self.Inner.Dy()-1 && rowNum < len(self.Rows); rowNum++ {
|
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]
|
row := self.Rows[rowNum]
|
||||||
y := (rowNum + 2) - self.TopRow
|
y := (rowNum + 2) - self.TopRow
|
||||||
|
|
||||||
|
@ -149,12 +152,12 @@ func (self *Table) calcPos() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Table) Up() {
|
func (self *Table) Up() {
|
||||||
self.SelectedRow -= 1
|
self.SelectedRow--
|
||||||
self.calcPos()
|
self.calcPos()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Table) Down() {
|
func (self *Table) Down() {
|
||||||
self.SelectedRow += 1
|
self.SelectedRow++
|
||||||
self.calcPos()
|
self.calcPos()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user