diff options
Diffstat (limited to 'layout')
-rw-r--r-- | layout/layout.go | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/layout/layout.go b/layout/layout.go index 0125223..359b47e 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -87,13 +87,28 @@ func processRow(c gotop.Config, numRows int, rowDefs [][]widgetRule) (ui.GridIte columns = append(columns, make([]interface{}, 0)) } colHeights := make([]int, numCols) - for _, rds := range processing { - for _, rd := range rds { + for i, row := range processing { + // A definition may fill up the columns before all rows are consumed, + // e.g. wid1/2 wid2/2. This block checks for that and, if it occurs, + // prepends the remaining rows to the "remainder" return value. + full := true + for _, ch := range colHeights { + if ch <= maxHeight { + full = false + break + } + } + if full { + rowDefs = append(processing[i:], rowDefs...) + break + } + // Not all rows have been consumed, so go ahead and place the row's widgets in columns + for _, wid := range row { for j, ch := range colHeights { - if ch+rd.Height <= maxHeight { - widget := makeWidget(c, rd) - columns[j] = append(columns[j], ui.NewRow(float64(rd.Height)/float64(maxHeight), widget)) - colHeights[j] += rd.Height + if ch+wid.Height <= maxHeight { + widget := makeWidget(c, wid) + columns[j] = append(columns[j], ui.NewRow(float64(wid.Height)/float64(maxHeight), widget)) + colHeights[j] += wid.Height break } } @@ -109,8 +124,12 @@ func processRow(c gotop.Config, numRows int, rowDefs [][]widgetRule) (ui.GridIte return ui.NewRow(1.0/float64(numRows), uiColumns...), rowDefs } +type Metric interface { + EnableMetric() +} + func makeWidget(c gotop.Config, widRule widgetRule) interface{} { - var w interface{} + var w Metric switch widRule.Widget { case "cpu": cpu := widgets.NewCpuWidget(c.UpdateInterval, c.GraphHorizontalScale, c.AverageLoad, c.PercpuLoad) @@ -131,7 +150,8 @@ func makeWidget(c gotop.Config, widRule widgetRule) interface{} { } w = cpu case "disk": - w = widgets.NewDiskWidget() + dw := widgets.NewDiskWidget() + w = dw case "mem": m := widgets.NewMemWidget(c.UpdateInterval, c.GraphHorizontalScale) m.LineColors["Main"] = ui.Color(c.Colorscheme.MainMem) @@ -179,6 +199,9 @@ func makeWidget(c gotop.Config, widRule widgetRule) interface{} { log.Printf("Invalid widget name %s. Must be one of %v", widRule.Widget, widgetNames) return ui.NewBlock() } + if c.ExportPort != "" { + w.EnableMetric() + } return w } |