mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
allow multi-line metadata in expanded view
This commit is contained in:
parent
6a8848d1e2
commit
c76036a6f2
@ -1,6 +1,8 @@
|
||||
package expanded
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
@ -24,12 +26,33 @@ func NewInfo(id string) *Info {
|
||||
|
||||
func (w *Info) Set(k, v string) {
|
||||
w.data[k] = v
|
||||
|
||||
// rebuild rows
|
||||
w.Rows = [][]string{}
|
||||
for _, k := range displayInfo {
|
||||
if v, ok := w.data[k]; ok {
|
||||
w.Rows = append(w.Rows, []string{k, v})
|
||||
w.Rows = append(w.Rows, mkInfoRows(k, v)...)
|
||||
}
|
||||
}
|
||||
|
||||
w.Height = len(w.Rows) + 2
|
||||
}
|
||||
|
||||
// Build row(s) from a key and value string
|
||||
func mkInfoRows(k, v string) (rows [][]string) {
|
||||
lines := strings.Split(v, "\n")
|
||||
|
||||
// initial row with field name
|
||||
rows = append(rows, []string{k, lines[0]})
|
||||
|
||||
// append any additional lines in seperate row
|
||||
if len(lines) > 1 {
|
||||
for _, line := range lines[1:] {
|
||||
if line != "" {
|
||||
rows = append(rows, []string{"", line})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user