mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
allow multi-line metadata in expanded view
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package expanded
|
package expanded
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,12 +26,33 @@ func NewInfo(id string) *Info {
|
|||||||
|
|
||||||
func (w *Info) Set(k, v string) {
|
func (w *Info) Set(k, v string) {
|
||||||
w.data[k] = v
|
w.data[k] = v
|
||||||
|
|
||||||
// rebuild rows
|
// rebuild rows
|
||||||
w.Rows = [][]string{}
|
w.Rows = [][]string{}
|
||||||
for _, k := range displayInfo {
|
for _, k := range displayInfo {
|
||||||
if v, ok := w.data[k]; ok {
|
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
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user