summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-02-27 12:49:03 -0600
committerSean E. Russell <ser@ser1.net>2020-02-27 12:51:59 -0600
commitb03566cd60335f9941b0dc0af011d649953db16e (patch)
treec1e59f302cd00cce70f1e400c3d0d083e3db51cf
parentd0e2acc791cc0442ae220fd5be6c69f8ac4d9c4e (diff)
Fixes #62, the one-column bug
Updates ticket info
-rw-r--r--CHANGELOG.md1
-rw-r--r--layout/layout.go28
-rw-r--r--layouts/kitchensink6
-rw-r--r--widgets/batterygauge.go2
4 files changed, 24 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 30a6fb1..30c9ad8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Keys not controlling process widget, #59
+- The one-column bug, #62
## [3.3.2] - ??
diff --git a/layout/layout.go b/layout/layout.go
index d5380a6..0579fd0 100644
--- a/layout/layout.go
+++ b/layout/layout.go
@@ -34,13 +34,19 @@ func Layout(wl layout, c gotop.Config) (*MyGrid, error) {
uiRows := make([][]interface{}, 0)
numRows := countNumRows(wl.Rows)
var uiRow []interface{}
+ maxHeight := 0
+ heights := make([]int, 0)
+ var h int
for len(rowDefs) > 0 {
- uiRow, rowDefs = processRow(c, numRows, rowDefs)
+ h, uiRow, rowDefs = processRow(c, numRows, rowDefs)
+ maxHeight += h
uiRows = append(uiRows, uiRow)
+ heights = append(heights, h)
}
rgs := make([]interface{}, 0)
- rh := 1.0 / float64(len(uiRows))
- for _, ur := range uiRows {
+ for i, ur := range uiRows {
+ rh := float64(heights[i]) / float64(maxHeight)
+ log.Printf("appending row %d with height %d", i, heights[i])
rgs = append(rgs, ui.NewRow(rh, ur...))
}
grid := &MyGrid{ui.NewGrid(), nil, nil}
@@ -58,17 +64,18 @@ func Layout(wl layout, c gotop.Config) (*MyGrid, error) {
// if there's a row span widget in the row; in this case, it'll consume as many
// rows as the largest row span object in the row, and produce an uber-row
// containing all that stuff. It returns a slice without the consumed elements.
-func processRow(c gotop.Config, numRows int, rowDefs [][]widgetRule) ([]interface{}, [][]widgetRule) {
- // FIXME: 2\:x\\n2\:y\\n2\:z\\na isn't laying out correctly
+func processRow(c gotop.Config, numRows int, rowDefs [][]widgetRule) (int, []interface{}, [][]widgetRule) {
+ log.Printf("got %d rows", len(rowDefs))
// Recursive function #3. See the comment in deepFindProc.
if len(rowDefs) < 1 {
- return nil, [][]widgetRule{}
+ return 0, nil, [][]widgetRule{}
}
// The height of the tallest widget in this row; the number of rows that
// will be consumed, and the overall height of the row that will be
// produced.
maxHeight := countMaxHeight([][]widgetRule{rowDefs[0]})
+ log.Printf("maxHeight %d", maxHeight)
var processing [][]widgetRule
if maxHeight < len(rowDefs) {
processing = rowDefs[0:maxHeight]
@@ -77,6 +84,7 @@ func processRow(c gotop.Config, numRows int, rowDefs [][]widgetRule) ([]interfac
processing = rowDefs[0:]
rowDefs = [][]widgetRule{}
}
+ log.Printf("consuming %d rows, %d remainder rows", len(processing), len(rowDefs))
var colWeights []float64
var columns [][]interface{}
numCols := len(processing[0])
@@ -91,7 +99,7 @@ func processRow(c gotop.Config, numRows int, rowDefs [][]widgetRule) ([]interfac
outer:
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,
+ // e.g. cpu/2 net/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 {
@@ -102,6 +110,7 @@ outer:
}
if full {
rowDefs = append(processing[i:], rowDefs...)
+ log.Printf("prepended early consumption; remainder now %d rows", len(rowDefs))
break
}
// Not all rows have been consumed, so go ahead and place the row's
@@ -120,7 +129,7 @@ outer:
}
// If all columns are full, break out, return the row, and continue processing
if !placed {
- rowDefs = processing[i:]
+ rowDefs = append(processing[i:], rowDefs...)
break outer
}
}
@@ -132,7 +141,8 @@ outer:
}
}
- return uiColumns, rowDefs
+ log.Printf("returning %d columns", len(uiColumns))
+ return maxHeight, uiColumns, rowDefs
}
type Metric interface {
diff --git a/layouts/kitchensink b/layouts/kitchensink
index 5e25894..71a542f 100644
--- a/layouts/kitchensink
+++ b/layouts/kitchensink
@@ -1,4 +1,4 @@
-cpu/2 mem/1
-3:temp/1 2:disk/2
+3:cpu/2 3:mem/1
+4:temp/1 3:disk/2
power
-net procs
+3:net 3:procs
diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go
index a84637c..59accfb 100644
--- a/widgets/batterygauge.go
+++ b/widgets/batterygauge.go
@@ -59,7 +59,7 @@ func (b *BatteryGauge) EnableMetric() {
func (self *BatteryGauge) update() {
bats, err := battery.GetAll()
if err != nil {
- log.Printf("error setting up metrics: %v", err)
+ log.Printf("error setting up batteries: %v", err)
return
}
mx := 0.0