mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add padding to column menu
This commit is contained in:
parent
6fe6e7c316
commit
f11a705b8b
@ -30,7 +30,6 @@ func (cg *CompactGrid) Align() {
|
|||||||
|
|
||||||
// update row ypos, width recursively
|
// update row ypos, width recursively
|
||||||
colWidths := cg.calcWidths()
|
colWidths := cg.calcWidths()
|
||||||
cg.header.SetWidths(cg.Width, colWidths)
|
|
||||||
for _, r := range cg.pageRows() {
|
for _, r := range cg.pageRows() {
|
||||||
r.SetY(y)
|
r.SetY(y)
|
||||||
y += r.GetHeight()
|
y += r.GetHeight()
|
||||||
|
24
menus.go
24
menus.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/config"
|
"github.com/bcicen/ctop/config"
|
||||||
@ -114,6 +115,12 @@ func SortMenu() MenuFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ColumnsMenu() MenuFn {
|
func ColumnsMenu() MenuFn {
|
||||||
|
const (
|
||||||
|
enabledStr = "[X]"
|
||||||
|
disabledStr = "[ ]"
|
||||||
|
padding = 2
|
||||||
|
)
|
||||||
|
|
||||||
ui.Clear()
|
ui.Clear()
|
||||||
ui.DefaultEvtStream.ResetHandlers()
|
ui.DefaultEvtStream.ResetHandlers()
|
||||||
defer ui.DefaultEvtStream.ResetHandlers()
|
defer ui.DefaultEvtStream.ResetHandlers()
|
||||||
@ -124,9 +131,24 @@ func ColumnsMenu() MenuFn {
|
|||||||
m.BorderLabel = "Columns"
|
m.BorderLabel = "Columns"
|
||||||
|
|
||||||
rebuild := func() {
|
rebuild := func() {
|
||||||
|
// get padding for right alignment of enabled status
|
||||||
|
var maxLen int
|
||||||
|
for _, col := range config.GlobalColumns {
|
||||||
|
if len(col.Label) > maxLen {
|
||||||
|
maxLen = len(col.Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maxLen += padding
|
||||||
|
|
||||||
|
// rebuild menu items
|
||||||
m.ClearItems()
|
m.ClearItems()
|
||||||
for _, col := range config.GlobalColumns {
|
for _, col := range config.GlobalColumns {
|
||||||
txt := fmt.Sprintf("%s [%t]", col.Label, col.Enabled)
|
txt := col.Label + strings.Repeat(" ", maxLen-len(col.Label))
|
||||||
|
if col.Enabled {
|
||||||
|
txt += enabledStr
|
||||||
|
} else {
|
||||||
|
txt += disabledStr
|
||||||
|
}
|
||||||
m.AddItems(menu.Item{col.Name, txt})
|
m.AddItems(menu.Item{col.Name, txt})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user