mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add status indicator, setstatus method
This commit is contained in:
parent
271a059d3a
commit
9671fffbe9
1
grid.go
1
grid.go
@ -89,6 +89,7 @@ func (g *Grid) redrawRows() {
|
|||||||
|
|
||||||
func fieldHeader() *ui.Row {
|
func fieldHeader() *ui.Row {
|
||||||
return ui.NewRow(
|
return ui.NewRow(
|
||||||
|
ui.NewCol(1, 0, headerPar("STATUS")),
|
||||||
ui.NewCol(2, 0, headerPar("NAME")),
|
ui.NewCol(2, 0, headerPar("NAME")),
|
||||||
ui.NewCol(2, 0, headerPar("CID")),
|
ui.NewCol(2, 0, headerPar("CID")),
|
||||||
ui.NewCol(2, 0, headerPar("CPU")),
|
ui.NewCol(2, 0, headerPar("CPU")),
|
||||||
|
@ -7,17 +7,23 @@ import (
|
|||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
mark = '\u25C9'
|
||||||
|
)
|
||||||
|
|
||||||
type ContainerWidgets interface {
|
type ContainerWidgets interface {
|
||||||
Row() *ui.Row
|
Row() *ui.Row
|
||||||
Render()
|
Render()
|
||||||
Highlight()
|
Highlight()
|
||||||
UnHighlight()
|
UnHighlight()
|
||||||
|
SetStatus(int)
|
||||||
SetCPU(int)
|
SetCPU(int)
|
||||||
SetNet(int64, int64)
|
SetNet(int64, int64)
|
||||||
SetMem(int64, int64, int)
|
SetMem(int64, int64, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Compact struct {
|
type Compact struct {
|
||||||
|
Status *ui.Par
|
||||||
Cid *ui.Par
|
Cid *ui.Par
|
||||||
Net *ui.Par
|
Net *ui.Par
|
||||||
Name *ui.Par
|
Name *ui.Par
|
||||||
@ -27,6 +33,7 @@ type Compact struct {
|
|||||||
|
|
||||||
func NewCompact(id string, name string) *Compact {
|
func NewCompact(id string, name string) *Compact {
|
||||||
return &Compact{
|
return &Compact{
|
||||||
|
Status: slimPar(string(mark)),
|
||||||
Cid: slimPar(id),
|
Cid: slimPar(id),
|
||||||
Net: slimPar("-"),
|
Net: slimPar("-"),
|
||||||
Name: slimPar(name),
|
Name: slimPar(name),
|
||||||
@ -39,7 +46,9 @@ func (w *Compact) Render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Compact) Row() *ui.Row {
|
func (w *Compact) Row() *ui.Row {
|
||||||
|
centerParText(w.Status)
|
||||||
return ui.NewRow(
|
return ui.NewRow(
|
||||||
|
ui.NewCol(1, 0, w.Status),
|
||||||
ui.NewCol(2, 0, w.Name),
|
ui.NewCol(2, 0, w.Name),
|
||||||
ui.NewCol(2, 0, w.Cid),
|
ui.NewCol(2, 0, w.Cid),
|
||||||
ui.NewCol(2, 0, w.Cpu),
|
ui.NewCol(2, 0, w.Cpu),
|
||||||
@ -58,6 +67,15 @@ func (w *Compact) UnHighlight() {
|
|||||||
w.Name.TextBgColor = ui.ColorDefault
|
w.Name.TextBgColor = ui.ColorDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Compact) SetStatus(val int) {
|
||||||
|
switch val {
|
||||||
|
case 0:
|
||||||
|
w.Status.TextFgColor = ui.ColorGreen
|
||||||
|
default:
|
||||||
|
w.Status.TextFgColor = ui.ColorRed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Compact) SetCPU(val int) {
|
func (w *Compact) SetCPU(val int) {
|
||||||
w.Cpu.BarColor = colorScale(val)
|
w.Cpu.BarColor = colorScale(val)
|
||||||
w.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
|
w.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
|
||||||
@ -83,6 +101,24 @@ func (w *Compact) SetMem(val int64, limit int64, percent int) {
|
|||||||
w.Memory.Percent = percent
|
w.Memory.Percent = percent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func centerParText(p *ui.Par) {
|
||||||
|
var text string
|
||||||
|
var padding string
|
||||||
|
|
||||||
|
// strip existing left-padding
|
||||||
|
for i, ch := range p.Text {
|
||||||
|
if string(ch) != " " {
|
||||||
|
text = p.Text[i:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
padlen := (p.InnerWidth() - len(text)) / 2
|
||||||
|
for i := 0; i < padlen; i++ {
|
||||||
|
padding += " "
|
||||||
|
}
|
||||||
|
p.Text = fmt.Sprintf("%s%s", padding, text)
|
||||||
|
}
|
||||||
|
|
||||||
func slimPar(s string) *ui.Par {
|
func slimPar(s string) *ui.Par {
|
||||||
p := ui.NewPar(s)
|
p := ui.NewPar(s)
|
||||||
p.Border = false
|
p.Border = false
|
||||||
|
@ -58,6 +58,9 @@ func (w *Expanded) Highlight() {
|
|||||||
func (w *Expanded) UnHighlight() {
|
func (w *Expanded) UnHighlight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Expanded) SetStatus(val int) {
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Expanded) SetCPU(val int) {
|
func (w *Expanded) SetCPU(val int) {
|
||||||
w.Cpu.Update(val)
|
w.Cpu.Update(val)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user