Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #130 from A-lxe/process-list-location-indicator
Browse files Browse the repository at this point in the history
Add a scroll location indicator to the process table
  • Loading branch information
cjbassi authored Apr 8, 2019
2 parents a31e182 + e7dff53 commit 56662fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/termui/table.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package termui

import (
"fmt"
"image"
"log"
"strings"
Expand All @@ -21,6 +22,8 @@ type Table struct {
ShowCursor bool
CursorColor Color

ShowLocation bool

UniqueCol int // the column used to uniquely identify each table row
SelectedItem string // used to keep the cursor on the correct item if the data changes
SelectedRow int
Expand All @@ -43,6 +46,10 @@ func NewTable() *Table {
func (self *Table) Draw(buf *Buffer) {
self.Block.Draw(buf)

if self.ShowLocation {
self.drawLocation(buf)
}

self.ColResizer()

// finds exact column starting position
Expand Down Expand Up @@ -121,6 +128,20 @@ func (self *Table) Draw(buf *Buffer) {
}
}

func (self *Table) drawLocation(buf *Buffer) {
total := len(self.Rows)
topRow := self.TopRow + 1
bottomRow := self.TopRow + self.Inner.Dy() - 1
if bottomRow > total {
bottomRow = total
}

loc := fmt.Sprintf(" %d - %d of %d ", topRow, bottomRow, total)

width := len(loc)
buf.SetString(loc, self.TitleStyle, image.Pt(self.Max.X-width-2, self.Min.Y))
}

// Scrolling ///////////////////////////////////////////////////////////////////

// calcPos is used to calculate the cursor position and the current view into the table.
Expand Down
1 change: 1 addition & 0 deletions src/widgets/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewProcWidget() *ProcWidget {
}
self.Title = " Processes "
self.ShowCursor = true
self.ShowLocation = true
self.ColGap = 3
self.PadLeft = 2
self.ColResizer = func() {
Expand Down

0 comments on commit 56662fd

Please sign in to comment.