implement full-row cursor highlighting

This commit is contained in:
Bradley Cicenas 2018-09-17 01:24:06 +00:00
parent ac5bed210f
commit cf352f7c8a
4 changed files with 68 additions and 10 deletions

View File

@ -57,11 +57,11 @@ func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
// Set an initial cursor position, if possible
func (gc *GridCursor) Reset() {
for _, c := range gc.cSource.All() {
c.Widgets.Name.UnHighlight()
c.Widgets.UnHighlight()
}
if gc.Len() > 0 {
gc.selectedID = gc.filtered[0].Id
gc.filtered[0].Widgets.Name.Highlight()
gc.filtered[0].Widgets.Highlight()
}
}
@ -109,9 +109,9 @@ func (gc *GridCursor) Up() {
active := gc.filtered[idx]
next := gc.filtered[idx-1]
active.Widgets.Name.UnHighlight()
active.Widgets.UnHighlight()
gc.selectedID = next.Id
next.Widgets.Name.Highlight()
next.Widgets.Highlight()
gc.ScrollPage()
ui.Render(cGrid)
@ -128,9 +128,9 @@ func (gc *GridCursor) Down() {
active := gc.filtered[idx]
next := gc.filtered[idx+1]
active.Widgets.Name.UnHighlight()
active.Widgets.UnHighlight()
gc.selectedID = next.Id
next.Widgets.Name.Highlight()
next.Widgets.Highlight()
gc.ScrollPage()
ui.Render(cGrid)
@ -151,9 +151,9 @@ func (gc *GridCursor) PgUp() {
active := gc.filtered[idx]
next := gc.filtered[nextidx]
active.Widgets.Name.UnHighlight()
active.Widgets.UnHighlight()
gc.selectedID = next.Id
next.Widgets.Name.Highlight()
next.Widgets.Highlight()
cGrid.Align()
ui.Render(cGrid)
@ -174,9 +174,9 @@ func (gc *GridCursor) PgDown() {
active := gc.filtered[idx]
next := gc.filtered[nextidx]
active.Widgets.Name.UnHighlight()
active.Widgets.UnHighlight()
gc.selectedID = next.Id
next.Widgets.Name.Highlight()
next.Widgets.Highlight()
cGrid.Align()
ui.Render(cGrid)

View File

@ -23,6 +23,16 @@ func (w *GaugeCol) Reset() {
w.Percent = 0
}
func (w *GaugeCol) Highlight() {
w.Bg = ui.ThemeAttr("par.text.fg")
w.PercentColor = ui.ThemeAttr("par.text.hi")
}
func (w *GaugeCol) UnHighlight() {
w.Bg = ui.ThemeAttr("par.text.bg")
w.PercentColor = ui.ThemeAttr("par.text.bg")
}
func colorScale(n int) ui.Attribute {
if n > 70 {
return ui.ThemeAttr("status.danger")

View File

@ -17,6 +17,7 @@ type Compact struct {
Net *TextCol
IO *TextCol
Pids *TextCol
Bg *RowBg
X, Y int
Width int
Height int
@ -36,6 +37,7 @@ func NewCompact(id string) *Compact {
Net: NewTextCol("-"),
IO: NewTextCol("-"),
Pids: NewTextCol("-"),
Bg: NewRowBg(),
X: 1,
Height: 1,
}
@ -90,6 +92,8 @@ func (row *Compact) SetY(y int) {
if y == row.Y {
return
}
row.Bg.Y = y
for _, col := range row.all() {
col.SetY(y)
}
@ -101,6 +105,10 @@ func (row *Compact) SetWidth(width int) {
return
}
x := row.X
row.Bg.SetX(x + colWidths[0] + 1)
row.Bg.SetWidth(width)
autoWidth := calcWidth(width)
for n, col := range row.all() {
if colWidths[n] != 0 {
@ -119,6 +127,7 @@ func (row *Compact) SetWidth(width int) {
func (row *Compact) Buffer() ui.Buffer {
buf := ui.NewBuffer()
buf.Merge(row.Bg.Buffer())
buf.Merge(row.Status.Buffer())
buf.Merge(row.Name.Buffer())
buf.Merge(row.Cid.Buffer())
@ -142,3 +151,40 @@ func (row *Compact) all() []ui.GridBufferer {
row.Pids,
}
}
func (row *Compact) Highlight() {
row.Bg.Highlight()
row.Name.Highlight()
row.Cid.Highlight()
row.Cpu.Highlight()
row.Mem.Highlight()
row.Net.Highlight()
row.IO.Highlight()
row.Pids.Highlight()
}
func (row *Compact) UnHighlight() {
row.Bg.UnHighlight()
row.Name.UnHighlight()
row.Cid.UnHighlight()
row.Cpu.UnHighlight()
row.Mem.UnHighlight()
row.Net.UnHighlight()
row.IO.UnHighlight()
row.Pids.UnHighlight()
}
type RowBg struct {
*ui.Par
}
func NewRowBg() *RowBg {
bg := ui.NewPar("")
bg.Height = 1
bg.Border = false
bg.Bg = ui.ThemeAttr("par.text.bg")
return &RowBg{bg}
}
func (w *RowBg) Highlight() { w.Bg = ui.ThemeAttr("par.text.fg") }
func (w *RowBg) UnHighlight() { w.Bg = ui.ThemeAttr("par.text.bg") }

View File

@ -17,11 +17,13 @@ func NewTextCol(s string) *TextCol {
}
func (w *TextCol) Highlight() {
w.Bg = ui.ThemeAttr("par.text.fg")
w.TextFgColor = ui.ThemeAttr("par.text.hi")
w.TextBgColor = ui.ThemeAttr("par.text.fg")
}
func (w *TextCol) UnHighlight() {
w.Bg = ui.ThemeAttr("par.text.bg")
w.TextFgColor = ui.ThemeAttr("par.text.fg")
w.TextBgColor = ui.ThemeAttr("par.text.bg")
}