summaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-03-27 14:27:23 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2018-03-27 14:27:23 -0700
commitdc8cc5aa4db5cc08ae01b2ce48b6d310b98e858f (patch)
tree32a769dd4a6c4beec588571a164fc5cdc7ef4600 /termui
parent0aa09f4fc6afc71624c8956bdfdd80a72b808cb0 (diff)
Change methods to use 'self' keyword
Diffstat (limited to 'termui')
-rw-r--r--termui/block.go70
-rw-r--r--termui/buffer.go50
-rw-r--r--termui/gauge.go24
-rw-r--r--termui/grid.go22
-rw-r--r--termui/linegraph.go34
-rw-r--r--termui/sparkline.go36
-rw-r--r--termui/table.go148
7 files changed, 192 insertions, 192 deletions
diff --git a/termui/block.go b/termui/block.go
index d6d9856..4695f25 100644
--- a/termui/block.go
+++ b/termui/block.go
@@ -32,69 +32,69 @@ func NewBlock() *Block {
}
}
-func (b *Block) drawBorder(buf *Buffer) {
- x := b.X + 1
- y := b.Y + 1
+func (self *Block) drawBorder(buf *Buffer) {
+ x := self.X + 1
+ y := self.Y + 1
// draw lines
- buf.Merge(NewFilledBuffer(0, 0, x, 1, Cell{HORIZONTAL_LINE, b.BorderFg, b.BorderBg}))
- buf.Merge(NewFilledBuffer(0, y, x, y+1, Cell{HORIZONTAL_LINE, b.BorderFg, b.BorderBg}))
- buf.Merge(NewFilledBuffer(0, 0, 1, y+1, Cell{VERTICAL_LINE, b.BorderFg, b.BorderBg}))
- buf.Merge(NewFilledBuffer(x, 0, x+1, y+1, Cell{VERTICAL_LINE, b.BorderFg, b.BorderBg}))
+ buf.Merge(NewFilledBuffer(0, 0, x, 1, Cell{HORIZONTAL_LINE, self.BorderFg, self.BorderBg}))
+ buf.Merge(NewFilledBuffer(0, y, x, y+1, Cell{HORIZONTAL_LINE, self.BorderFg, self.BorderBg}))
+ buf.Merge(NewFilledBuffer(0, 0, 1, y+1, Cell{VERTICAL_LINE, self.BorderFg, self.BorderBg}))
+ buf.Merge(NewFilledBuffer(x, 0, x+1, y+1, Cell{VERTICAL_LINE, self.BorderFg, self.BorderBg}))
// draw corners
- buf.SetCell(0, 0, Cell{TOP_LEFT, b.BorderFg, b.BorderBg})
- buf.SetCell(x, 0, Cell{TOP_RIGHT, b.BorderFg, b.BorderBg})
- buf.SetCell(0, y, Cell{BOTTOM_LEFT, b.BorderFg, b.BorderBg})
- buf.SetCell(x, y, Cell{BOTTOM_RIGHT, b.BorderFg, b.BorderBg})
+ buf.SetCell(0, 0, Cell{TOP_LEFT, self.BorderFg, self.BorderBg})
+ buf.SetCell(x, 0, Cell{TOP_RIGHT, self.BorderFg, self.BorderBg})
+ buf.SetCell(0, y, Cell{BOTTOM_LEFT, self.BorderFg, self.BorderBg})
+ buf.SetCell(x, y, Cell{BOTTOM_RIGHT, self.BorderFg, self.BorderBg})
}
-func (b *Block) drawLabel(buf *Buffer) {
- r := MaxString(b.Label, (b.X-3)-1)
- buf.SetString(3, 0, r, b.LabelFg, b.LabelBg)
- if b.Label == "" {
+func (self *Block) drawLabel(buf *Buffer) {
+ r := MaxString(self.Label, (self.X-3)-1)
+ buf.SetString(3, 0, r, self.LabelFg, self.LabelBg)
+ if self.Label == "" {
return
}
- c := Cell{' ', b.Fg, b.Bg}
+ c := Cell{' ', self.Fg, self.Bg}
buf.SetCell(2, 0, c)
- if len(b.Label)+3 < b.X {
- buf.SetCell(len(b.Label)+3, 0, c)
+ if len(self.Label)+3 < self.X {
+ buf.SetCell(len(self.Label)+3, 0, c)
} else {
- buf.SetCell(b.X-1, 0, c)
+ buf.SetCell(self.X-1, 0, c)
}
}
// Resize computes Height, Width, XOffset, and YOffset given terminal dimensions.
-func (b *Block) Resize(termWidth, termHeight, termCols, termRows int) {
- b.X = int((float64(b.Grid.Dx())/float64(termCols))*float64(termWidth)) - 2
- b.Y = int((float64(b.Grid.Dy())/float64(termRows))*float64(termHeight)) - 2
- b.XOffset = int((float64(b.Grid.Min.X) / float64(termCols)) * float64(termWidth))
- b.YOffset = int((float64(b.Grid.Min.Y) / float64(termRows)) * float64(termHeight))
+func (self *Block) Resize(termWidth, termHeight, termCols, termRows int) {
+ self.X = int((float64(self.Grid.Dx())/float64(termCols))*float64(termWidth)) - 2
+ self.Y = int((float64(self.Grid.Dy())/float64(termRows))*float64(termHeight)) - 2
+ self.XOffset = int((float64(self.Grid.Min.X) / float64(termCols)) * float64(termWidth))
+ self.YOffset = int((float64(self.Grid.Min.Y) / float64(termRows)) * float64(termHeight))
}
// SetGrid create a rectangle representing the block's dimensions in the grid.
-func (b *Block) SetGrid(c0, r0, c1, r1 int) {
- b.Grid = image.Rect(c0, r0, c1, r1)
+func (self *Block) SetGrid(c0, r0, c1, r1 int) {
+ self.Grid = image.Rect(c0, r0, c1, r1)
}
// GetXOffset implements Bufferer interface.
-func (b *Block) GetXOffset() int {
- return b.XOffset
+func (self *Block) GetXOffset() int {
+ return self.XOffset
}
// GetYOffset implements Bufferer interface.
-func (b *Block) GetYOffset() int {
- return b.YOffset
+func (self *Block) GetYOffset() int {
+ return self.YOffset
}
// Buffer implements Bufferer interface and draws background, border, and borderlabel.
-func (b *Block) Buffer() *Buffer {
+func (self *Block) Buffer() *Buffer {
buf := NewBuffer()
- buf.SetAreaXY(b.X+2, b.Y+2)
- buf.Fill(Cell{' ', ColorDefault, b.Bg})
+ buf.SetAreaXY(self.X+2, self.Y+2)
+ buf.Fill(Cell{' ', ColorDefault, self.Bg})
- b.drawBorder(buf)
- b.drawLabel(buf)
+ self.drawBorder(buf)
+ self.drawLabel(buf)
return buf
}
diff --git a/termui/buffer.go b/termui/buffer.go
index 47c234c..9faabaf 100644
--- a/termui/buffer.go
+++ b/termui/buffer.go
@@ -40,60 +40,60 @@ func NewFilledBuffer(x0, y0, x1, y1 int, c Cell) *Buffer {
}
// SetCell assigns a Cell to (x,y).
-func (b *Buffer) SetCell(x, y int, c Cell) {
- b.CellMap[image.Pt(x, y)] = c
+func (self *Buffer) SetCell(x, y int, c Cell) {
+ self.CellMap[image.Pt(x, y)] = c
}
// SetString assigns a string to a Buffer starting at (x,y).
-func (b *Buffer) SetString(x, y int, s string, fg, bg Color) {
+func (self *Buffer) SetString(x, y int, s string, fg, bg Color) {
for i, char := range s {
- b.SetCell(x+i, y, Cell{char, fg, bg})
+ self.SetCell(x+i, y, Cell{char, fg, bg})
}
}
// At returns the cell at (x,y).
-func (b *Buffer) At(x, y int) Cell {
- return b.CellMap[image.Pt(x, y)]
+func (self *Buffer) At(x, y int) Cell {
+ return self.CellMap[image.Pt(x, y)]
}
-// SetArea assigns a new rect area to Buffer b.
-func (b *Buffer) SetArea(r image.Rectangle) {
- b.Area.Max = r.Max
- b.Area.Min = r.Min
+// SetArea assigns a new rect area to self.
+func (self *Buffer) SetArea(r image.Rectangle) {
+ self.Area.Max = r.Max
+ self.Area.Min = r.Min
}
// SetAreaXY sets the Buffer bounds from (0,0) to (x,y).
-func (b *Buffer) SetAreaXY(x, y int) {
- b.Area.Min.Y = 0
- b.Area.Min.X = 0
- b.Area.Max.Y = y
- b.Area.Max.X = x
+func (self *Buffer) SetAreaXY(x, y int) {
+ self.Area.Min.Y = 0
+ self.Area.Min.X = 0
+ self.Area.Max.Y = y
+ self.Area.Max.X = x
}
// Merge merges the given buffers onto the current Buffer.
-func (b *Buffer) Merge(bs ...*Buffer) {
+func (self *Buffer) Merge(bs ...*Buffer) {
for _, buf := range bs {
for p, c := range buf.CellMap {
- b.SetCell(p.X, p.Y, c)
+ self.SetCell(p.X, p.Y, c)
}
- b.SetArea(b.Area.Union(buf.Area))
+ self.SetArea(self.Area.Union(buf.Area))
}
}
// MergeWithOffset merges a Buffer onto another with an offset.
-func (b *Buffer) MergeWithOffset(buf *Buffer, xOffset, yOffset int) {
+func (self *Buffer) MergeWithOffset(buf *Buffer, xOffset, yOffset int) {
for p, c := range buf.CellMap {
- b.SetCell(p.X+xOffset, p.Y+yOffset, c)
+ self.SetCell(p.X+xOffset, p.Y+yOffset, c)
}
rect := image.Rect(xOffset, yOffset, buf.Area.Max.X+xOffset, buf.Area.Max.Y+yOffset)
- b.SetArea(b.Area.Union(rect))
+ self.SetArea(self.Area.Union(rect))
}
// Fill fills the Buffer with a Cell.
-func (b *Buffer) Fill(c Cell) {
- for x := b.Area.Min.X; x < b.Area.Max.X; x++ {
- for y := b.Area.Min.Y; y < b.Area.Max.Y; y++ {
- b.SetCell(x, y, c)
+func (self *Buffer) Fill(c Cell) {
+ for x := self.Area.Min.X; x < self.Area.Max.X; x++ {
+ for y := self.Area.Min.Y; y < self.Area.Max.Y; y++ {
+ self.SetCell(x, y, c)
}
}
}
diff --git a/termui/gauge.go b/termui/gauge.go
index 1896871..a5b3b2a 100644
--- a/termui/gauge.go
+++ b/termui/gauge.go
@@ -21,27 +21,27 @@ func NewGauge() *Gauge {
}
// Buffer implements Bufferer interface.
-func (g *Gauge) Buffer() *Buffer {
- buf := g.Block.Buffer()
+func (self *Gauge) Buffer() *Buffer {
+ buf := self.Block.Buffer()
// plot bar
- width := g.Percent * g.X / 100
- for y := 1; y <= g.Y; y++ {
+ width := self.Percent * self.X / 100
+ for y := 1; y <= self.Y; y++ {
for x := 1; x <= width; x++ {
- buf.SetCell(x, y, Cell{' ', g.GaugeColor, g.GaugeColor})
+ buf.SetCell(x, y, Cell{' ', self.GaugeColor, self.GaugeColor})
}
}
// plot percentage
- s := strconv.Itoa(g.Percent) + "%" + g.Description
- s = MaxString(s, g.X)
- y := (g.Y + 1) / 2
- x := ((g.X - len(s)) + 1) / 2
+ s := strconv.Itoa(self.Percent) + "%" + self.Description
+ s = MaxString(s, self.X)
+ y := (self.Y + 1) / 2
+ x := ((self.X - len(s)) + 1) / 2
for i, char := range s {
- bg := g.Bg
- fg := g.Fg
+ bg := self.Bg
+ fg := self.Fg
if x+i < width {
- fg = g.GaugeColor
+ fg = self.GaugeColor
bg = AttrReverse
}
buf.SetCell(1+x+i, y, Cell{char, fg, bg})
diff --git a/termui/grid.go b/termui/grid.go
index a005234..58b4839 100644
--- a/termui/grid.go
+++ b/termui/grid.go
@@ -25,7 +25,7 @@ func NewGrid() *Grid {
}
// Set assigns a widget and its grid dimensions to Grid.
-func (g *Grid) Set(x0, y0, x1, y1 int, widget GridBufferer) {
+func (self *Grid) Set(x0, y0, x1, y1 int, widget GridBufferer) {
if widget == nil {
return
}
@@ -34,33 +34,33 @@ func (g *Grid) Set(x0, y0, x1, y1 int, widget GridBufferer) {
}
widget.SetGrid(x0, y0, x1, y1)
- widget.Resize(g.Width, g.Height, g.Cols, g.Rows)
+ widget.Resize(self.Width, self.Height, self.Cols, self.Rows)
- g.Widgets = append(g.Widgets, widget)
+ self.Widgets = append(self.Widgets, widget)
}
// Resize resizes each widget in the grid.
-func (g *Grid) Resize() {
- for _, w := range g.Widgets {
- w.Resize(g.Width, g.Height, g.Cols, g.Rows)
+func (self *Grid) Resize() {
+ for _, w := range self.Widgets {
+ w.Resize(self.Width, self.Height, self.Cols, self.Rows)
}
}
// Buffer implements the Bufferer interface by merging each widget in Grid into one buffer.
-func (g *Grid) Buffer() *Buffer {
- buf := NewFilledBuffer(0, 0, g.Width, g.Height, Cell{' ', ColorDefault, Theme.Bg})
- for _, w := range g.Widgets {
+func (self *Grid) Buffer() *Buffer {
+ buf := NewFilledBuffer(0, 0, self.Width, self.Height, Cell{' ', ColorDefault, Theme.Bg})
+ for _, w := range self.Widgets {
buf.MergeWithOffset(w.Buffer(), w.GetXOffset(), w.GetYOffset())
}
return buf
}
// GetXOffset implements Bufferer interface.
-func (g *Grid) GetXOffset() int {
+func (self *Grid) GetXOffset() int {
return 0
}
// GetYOffset implements Bufferer interface.
-func (g *Grid) GetYOffset() int {
+func (self *Grid) GetYOffset() int {
return 0
}
diff --git a/termui/linegraph.go b/termui/linegraph.go
index 01d8414..cc71e8f 100644
--- a/termui/linegraph.go
+++ b/termui/linegraph.go
@@ -30,21 +30,21 @@ func NewLineGraph() *LineGraph {
}
// Buffer implements Bufferer interface.
-func (lc *LineGraph) Buffer() *Buffer {
- buf := lc.Block.Buffer()
+func (self *LineGraph) Buffer() *Buffer {
+ buf := self.Block.Buffer()
// we render each data point on to the canvas then copy over the braille to the buffer at the end
// fyi braille characters have 2x4 dots for each character
c := drawille.NewCanvas()
// used to keep track of the braille colors until the end when we render the braille to the buffer
- colors := make([][]Color, lc.X+2)
+ colors := make([][]Color, self.X+2)
for i := range colors {
- colors[i] = make([]Color, lc.Y+2)
+ colors[i] = make([]Color, self.Y+2)
}
// sort the series so that overlapping data will overlap the same way each time
- seriesList := make([]string, len(lc.Data))
+ seriesList := make([]string, len(self.Data))
i := 0
- for seriesName := range lc.Data {
+ for seriesName := range self.Data {
seriesList[i] = seriesName
i++
}
@@ -53,21 +53,21 @@ func (lc *LineGraph) Buffer() *Buffer {
// draw lines in reverse order so that the first color defined in the colorscheme is on top
for i := len(seriesList) - 1; i >= 0; i-- {
seriesName := seriesList[i]
- seriesData := lc.Data[seriesName]
- seriesLineColor, ok := lc.LineColor[seriesName]
+ seriesData := self.Data[seriesName]
+ seriesLineColor, ok := self.LineColor[seriesName]
if !ok {
- seriesLineColor = lc.DefaultLineColor
+ seriesLineColor = self.DefaultLineColor
}
// coordinates of last point
lastY, lastX := -1, -1
// assign colors to `colors` and lines/points to the canvas
for i := len(seriesData) - 1; i >= 0; i-- {
- x := ((lc.X + 1) * 2) - 1 - (((len(seriesData) - 1) - i) * lc.Zoom)
- y := ((lc.Y + 1) * 4) - 1 - int((float64((lc.Y)*4)-1)*(seriesData[i]/100))
+ x := ((self.X + 1) * 2) - 1 - (((len(seriesData) - 1) - i) * self.Zoom)
+ y := ((self.Y + 1) * 4) - 1 - int((float64((self.Y)*4)-1)*(seriesData[i]/100))
if x < 0 {
// render the line to the last point up to the wall
- if x > 0-lc.Zoom {
+ if x > 0-self.Zoom {
for _, p := range drawille.Line(lastX, lastY, x, y) {
if p.X > 0 {
c.Set(p.X, p.Y)
@@ -97,7 +97,7 @@ func (lc *LineGraph) Buffer() *Buffer {
continue
}
if char != 10240 { // empty braille character
- buf.SetCell(x, y, Cell{char, colors[x][y], lc.Bg})
+ buf.SetCell(x, y, Cell{char, colors[x][y], self.Bg})
}
}
}
@@ -106,17 +106,17 @@ func (lc *LineGraph) Buffer() *Buffer {
// renders key ontop
for j, seriesName := range seriesList {
// sorts lines again
- seriesData := lc.Data[seriesName]
- seriesLineColor, ok := lc.LineColor[seriesName]
+ seriesData := self.Data[seriesName]
+ seriesLineColor, ok := self.LineColor[seriesName]
if !ok {
- seriesLineColor = lc.DefaultLineColor
+ seriesLineColor = self.DefaultLineColor
}
// render key ontop, but let braille be drawn over space characters
str := fmt.Sprintf("%s %3.0f%%", seriesName, seriesData[len(seriesData)-1])
for k, char := range str {
if char != ' ' {
- buf.SetCell(3+k, j+2, Cell{char, seriesLineColor, lc.Bg})
+ buf.SetCell(3+k, j+2, Cell{char, seriesLineColor, self.Bg})
}
}
diff --git a/termui/sparkline.go b/termui/sparkline.go
index 6beeb8d..8cefff8 100644
--- a/termui/sparkline.go
+++ b/termui/sparkline.go
@@ -18,8 +18,8 @@ type Sparklines struct {
}
// Add appends a given Sparkline to the *Sparklines.
-func (s *Sparklines) Add(sl Sparkline) {
- s.Lines = append(s.Lines, &sl)
+func (self *Sparklines) Add(sl Sparkline) {
+ self.Lines = append(self.Lines, &sl)
}
// NewSparkline returns an unrenderable single sparkline that intended to be added into a Sparklines.
@@ -39,37 +39,37 @@ func NewSparklines(ss ...*Sparkline) *Sparklines {
}
// Buffer implements Bufferer interface.
-func (sl *Sparklines) Buffer() *Buffer {
- buf := sl.Block.Buffer()
+func (self *Sparklines) Buffer() *Buffer {
+ buf := self.Block.Buffer()
- lc := len(sl.Lines) // lineCount
+ lc := len(self.Lines) // lineCount
// renders each sparkline and its titles
- for i, line := range sl.Lines {
+ for i, line := range self.Lines {
// prints titles
- title1Y := 2 + (sl.Y/lc)*i
- title2Y := (2 + (sl.Y/lc)*i) + 1
- title1 := MaxString(line.Title1, sl.X)
- title2 := MaxString(line.Title2, sl.X)
- buf.SetString(1, title1Y, title1, line.TitleColor|AttrBold, sl.Bg)
- buf.SetString(1, title2Y, title2, line.TitleColor|AttrBold, sl.Bg)
+ title1Y := 2 + (self.Y/lc)*i
+ title2Y := (2 + (self.Y/lc)*i) + 1
+ title1 := MaxString(line.Title1, self.X)
+ title2 := MaxString(line.Title2, self.X)
+ buf.SetString(1, title1Y, title1, line.TitleColor|AttrBold, self.Bg)
+ buf.SetString(1, title2Y, title2, line.TitleColor|AttrBold, self.Bg)
- sparkY := (sl.Y / lc) * (i + 1)
+ sparkY := (self.Y / lc) * (i + 1)
// finds max data in current view used for relative heights
max := 1
- for i := len(line.Data) - 1; i >= 0 && sl.X-((len(line.Data)-1)-i) >= 1; i-- {
+ for i := len(line.Data) - 1; i >= 0 && self.X-((len(line.Data)-1)-i) >= 1; i-- {
if line.Data[i] > max {
max = line.Data[i]
}
}
// prints sparkline
- for x := sl.X; x >= 1; x-- {
+ for x := self.X; x >= 1; x-- {
char := SPARKS[0]
- if (sl.X - x) < len(line.Data) {
- char = SPARKS[int((float64(line.Data[(len(line.Data)-1)-(sl.X-x)])/float64(max))*7)]
+ if (self.X - x) < len(line.Data) {
+ char = SPARKS[int((float64(line.Data[(len(line.Data)-1)-(self.X-x)])/float64(max))*7)]
}
- buf.SetCell(x, sparkY, Cell{char, line.LineColor, sl.Bg})
+ buf.SetCell(x, sparkY, Cell{char, line.LineColor, self.Bg})
}
}
diff --git a/termui/table.go b/termui/table.go
index 7e377d2..e24031b 100644
--- a/termui/table.go
+++ b/termui/table.go
@@ -22,82 +22,82 @@ type Table struct {
// NewTable returns a new Table instance
func NewTable() *Table {
- t := &Table{
+ self := &Table{
Block: NewBlock(),
Cursor: Theme.TableCursor,
SelectedRow: 0,
TopRow: 0,
UniqueCol: 0,
}
- t.ColResizer = t.ColResize
- return t
+ self.ColResizer = self.ColResize
+ return self
}
// ColResize is the default column resizer, but can be overriden.
// ColResize calculates the width of each column.
-func (t *Table) ColResize() {
+func (self *Table) ColResize() {
// calculate gap size based on total width
- t.Gap = 3
- if t.X < 50 {
- t.Gap = 1
- } else if t.X < 75 {
- t.Gap = 2
+ self.Gap = 3
+ if self.X < 50 {
+ self.Gap = 1
+ } else if self.X < 75 {
+ self.Gap = 2
}
cur := 0
- for _, w := range t.ColWidths {
- cur += t.Gap
- t.CellXPos = append(t.CellXPos, cur)
+ for _, w := range self.ColWidths {
+ cur += self.Gap
+ self.CellXPos = append(self.CellXPos, cur)
cur += w
}
}
// Buffer implements the Bufferer interface.
-func (t *Table) Buffer() *Buffer {
- buf := t.Block.Buffer()
+func (self *Table) Buffer() *Buffer {
+ buf := self.Block.Buffer()
// removes gap at the bottom of the current view if there is one
- if t.TopRow > len(t.Rows)-(t.Y-1) {
- t.TopRow = len(t.Rows) - (t.Y - 1)
+ if self.TopRow > len(self.Rows)-(self.Y-1) {
+ self.TopRow = len(self.Rows) - (self.Y - 1)
}
- t.ColResizer()
+ self.ColResizer()
// prints header
- for i, width := range t.ColWidths {
+ for i, width := range self.ColWidths {
if width == 0 {
break
}
- r := MaxString(t.Header[i], t.X-6)
- buf.SetString(t.CellXPos[i], 1, r, t.Fg|AttrBold, t.Bg)
+ r := MaxString(self.Header[i], self.X-6)
+ buf.SetString(self.CellXPos[i], 1, r, self.Fg|AttrBold, self.Bg)
}
// prints each row
- for rowNum := t.TopRow; rowNum < t.TopRow+t.Y-1 && rowNum < len(t.Rows); rowNum++ {
- row := t.Rows[rowNum]
- y := (rowNum + 2) - t.TopRow
+ for rowNum := self.TopRow; rowNum < self.TopRow+self.Y-1 && rowNum < len(self.Rows); rowNum++ {
+ row := self.Rows[rowNum]
+ y := (rowNum + 2) - self.TopRow
// prints cursor
- bg := t.Bg
- if (t.SelectedItem == "" && rowNum == t.SelectedRow) || (t.SelectedItem != "" && t.SelectedItem == row[t.UniqueCol]) {
- bg = t.Cursor
- for _, width := range t.ColWidths {
+ bg := self.Bg
+ if (self.SelectedItem == "" && rowNum == self.SelectedRow) || (self.SelectedItem != "" && self.SelectedItem == row[self.UniqueCol]) {
+ bg = self.Cursor
+ for _, width := range self.ColWidths {
if width == 0 {
break
}
- buf.SetString(1, y, strings.Repeat(" ", t.X), t.Fg, bg)
+ buf.SetString(1, y, strings.Repeat(" ", self.X), self.Fg, bg)
}
- t.SelectedItem = row[t.UniqueCol]
- t.SelectedRow = rowNum
+ self.SelectedItem = row[self.UniqueCol]
+ self.SelectedRow = rowNum
}
// prints each col of the row
- for i, width := range t.ColWidths {
+ for i, width := range self.ColWidths {
if width == 0 {
break
}
- r := MaxString(row[i], t.X-6)
- buf.SetString(t.CellXPos[i], y, r, t.Fg, bg)
+ r := MaxString(row[i], self.X-6)
+ buf.SetString(self.CellXPos[i], y, r, self.Fg, bg)
}
}
@@ -109,71 +109,71 @@ func (t *Table) Buffer() *Buffer {
/////////////////////////////////////////////////////////////////////////////////
// calcPos is used to calculate the cursor position and the current view.
-func (t *Table) calcPos() {
- t.SelectedItem = ""
+func (self *Table) calcPos() {
+ self.SelectedItem = ""
- if t.SelectedRow < 0 {
- t.SelectedRow = 0
+ if self.SelectedRow < 0 {
+ self.SelectedRow = 0
}
- if t.SelectedRow < t.TopRow {
- t.TopRow = t.SelectedRow
+ if self.SelectedRow < self.TopRow {
+ self.TopRow = self.SelectedRow
}
- if t.SelectedRow > len(t.Rows)-1 {
- t.SelectedRow = len(t.Rows) - 1
+ if self.SelectedRow > len(self.Rows)-1 {
+ self.SelectedRow = len(self.Rows) - 1
}
- if t.SelectedRow > t.TopRow+(t.Y-2) {
- t.TopRow = t.SelectedRow - (t.Y - 2)
+ if self.SelectedRow > self.TopRow+(self.Y-2) {
+ self.TopRow = self.SelectedRow - (self.Y - 2)
}
}
-func (t *Table) Up() {
- t.SelectedRow -= 1
- t.calcPos()
+func (self *Table) Up() {
+ self.SelectedRow -= 1
+ self.calcPos()
}
-func (t *Table) Down() {
- t.SelectedRow += 1
- t.calcPos()
+func (self *Table) Down() {
+ self.SelectedRow += 1
+ self.calcPos()
}
-func (t *Table) Top() {
- t.SelectedRow = 0
- t.calcPos()
+func (self *Table) Top() {
+ self.SelectedRow = 0
+ self.calcPos()
}
-func (t *Table) Bottom() {
- t.SelectedRow = len(t.Rows) - 1
- t.calcPos()
+func (self *Table) Bottom() {
+ self.SelectedRow = len(self.Rows) - 1
+ self.calcPos()
}
-// The number of lines in a page is equal to the height of the widget.
+// The number of lines in a page is equal to the height of the widgeself.
-func (t *Table) HalfPageUp() {
- t.SelectedRow = t.SelectedRow - (t.Y-2)/2
- t.calcPos()
+func (self *Table) HalfPageUp() {
+ self.SelectedRow = self.SelectedRow - (self.Y-2)/2
+ self.calcPos()
}
-func (t *Table) HalfPageDown() {
- t.SelectedRow = t.SelectedRow + (t.Y-2)/2
- t.calcPos()
+func (self *Table) HalfPageDown() {
+ self.SelectedRow = self.SelectedRow + (self.Y-2)/2
+ self.calcPos()
}
-func (t *Table) PageUp() {
- t.SelectedRow -= (t.Y - 2)
- t.calcPos()
+func (self *Table) PageUp() {
+ self.SelectedRow -= (self.Y - 2)
+ self.calcPos()
}
-func (t *Table) PageDown() {
- t.SelectedRow += (t.Y - 2)
- t.calcPos()
+func (self *Table) PageDown() {
+ self.SelectedRow += (self.Y - 2)
+ self.calcPos()
}
-func (t *Table) Click(x, y int) {
- x = x - t.XOffset
- y = y - t.YOffset
- if (x > 0 && x <= t.X) && (y > 0 && y <= t.Y) {
- t.SelectedRow = (t.TopRow + y) - 2
- t.calcPos()
+func (self *Table) Click(x, y int) {
+ x = x - self.XOffset
+ y = y - self.YOffset
+ if (x > 0 && x <= self.X) && (y > 0 && y <= self.Y) {
+ self.SelectedRow = (self.TopRow + y) - 2
+ self.calcPos()
}
}