mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add common column width calculation method, global column spacing
This commit is contained in:
parent
05b50af87b
commit
4aaf26b63d
@ -11,8 +11,10 @@ import (
|
|||||||
var log = logging.Init()
|
var log = logging.Init()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mark = string('\u25C9')
|
mark = string('\u25C9')
|
||||||
vBar = string('\u25AE')
|
vBar = string('\u25AE')
|
||||||
|
colSpacing = 1
|
||||||
|
statusWidth = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
type CompactGrid struct {
|
type CompactGrid struct {
|
||||||
@ -85,10 +87,15 @@ func NewCompactHeader() *CompactHeader {
|
|||||||
return header
|
return header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate per-column width, given total width and number of items
|
||||||
|
func calcWidth(width, items int) int {
|
||||||
|
spacing := colSpacing * items
|
||||||
|
return (width - statusWidth - spacing) / items
|
||||||
|
}
|
||||||
|
|
||||||
func (c *CompactHeader) SetWidth(w int) {
|
func (c *CompactHeader) SetWidth(w int) {
|
||||||
x := 1
|
x := 1
|
||||||
statusWidth := 3
|
autoWidth := calcWidth(w, 5)
|
||||||
autoWidth := (w - statusWidth) / 5
|
|
||||||
for n, col := range c.pars {
|
for n, col := range c.pars {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
@ -98,7 +105,7 @@ func (c *CompactHeader) SetWidth(w int) {
|
|||||||
}
|
}
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
col.SetWidth(autoWidth)
|
col.SetWidth(autoWidth)
|
||||||
x += autoWidth
|
x += autoWidth + colSpacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +169,7 @@ func (w *Compact) SetY(y int) {
|
|||||||
|
|
||||||
func (w *Compact) SetWidth(width int) {
|
func (w *Compact) SetWidth(width int) {
|
||||||
x := 1
|
x := 1
|
||||||
statusWidth := 3
|
autoWidth := calcWidth(width, 5)
|
||||||
autoWidth := (width - statusWidth) / 5
|
|
||||||
for n, col := range w.all() {
|
for n, col := range w.all() {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
@ -173,7 +179,7 @@ func (w *Compact) SetWidth(width int) {
|
|||||||
}
|
}
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
col.SetWidth(autoWidth)
|
col.SetWidth(autoWidth)
|
||||||
x += autoWidth
|
x += autoWidth + colSpacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,6 +293,5 @@ func slimGauge() *ui.Gauge {
|
|||||||
g.PaddingBottom = 0
|
g.PaddingBottom = 0
|
||||||
g.BarColor = ui.ColorGreen
|
g.BarColor = ui.ColorGreen
|
||||||
g.Label = "-"
|
g.Label = "-"
|
||||||
g.Bg = ui.ColorBlack
|
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user