From 0f2a5d1e9a0f70da7dedd21117318a7dc25b0199 Mon Sep 17 00:00:00 2001 From: Alex Aubuchon Date: Fri, 22 Mar 2019 18:03:00 -0400 Subject: [PATCH] Add a scroll location indicator to the process table --- src/termui/table.go | 22 ++++++++++++++++++++++ src/widgets/proc.go | 1 + 2 files changed, 23 insertions(+) diff --git a/src/termui/table.go b/src/termui/table.go index a6839a1..de34629 100644 --- a/src/termui/table.go +++ b/src/termui/table.go @@ -1,6 +1,7 @@ package termui import ( + "fmt" "image" "log" "strings" @@ -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 @@ -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 @@ -121,6 +128,21 @@ func (self *Table) Draw(buf *Buffer) { } } +// drawLoca +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. diff --git a/src/widgets/proc.go b/src/widgets/proc.go index fcece34..d48ed9a 100644 --- a/src/widgets/proc.go +++ b/src/widgets/proc.go @@ -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() {