mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add static width for specific columns
This commit is contained in:
@@ -12,7 +12,7 @@ type CompactHeader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCompactHeader() *CompactHeader {
|
func NewCompactHeader() *CompactHeader {
|
||||||
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX", "IO R/W", "Pids"}
|
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX", "IO R/W", "PIDS"}
|
||||||
ch := &CompactHeader{}
|
ch := &CompactHeader{}
|
||||||
ch.Height = 2
|
ch.Height = 2
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
@@ -27,13 +27,13 @@ func (ch *CompactHeader) GetHeight() int {
|
|||||||
|
|
||||||
func (ch *CompactHeader) SetWidth(w int) {
|
func (ch *CompactHeader) SetWidth(w int) {
|
||||||
x := ch.X
|
x := ch.X
|
||||||
autoWidth := calcWidth(w, 7)
|
autoWidth := calcWidth(w)
|
||||||
for n, col := range ch.pars {
|
for n, col := range ch.pars {
|
||||||
// set status column to static width
|
// set column to static width
|
||||||
if n == 0 {
|
if colWidths[n] != 0 {
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
col.SetWidth(statusWidth)
|
col.SetWidth(colWidths[n])
|
||||||
x += statusWidth
|
x += colWidths[n]
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
|
|||||||
@@ -99,13 +99,12 @@ func (row *Compact) SetWidth(width int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
x := row.X
|
x := row.X
|
||||||
autoWidth := calcWidth(width, 7)
|
autoWidth := calcWidth(width)
|
||||||
for n, col := range row.all() {
|
for n, col := range row.all() {
|
||||||
// set status column to static width
|
if colWidths[n] != 0 {
|
||||||
if n == 0 {
|
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
col.SetWidth(statusWidth)
|
col.SetWidth(colWidths[n])
|
||||||
x += statusWidth
|
x += colWidths[n]
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
col.SetX(x)
|
col.SetX(x)
|
||||||
|
|||||||
@@ -9,10 +9,29 @@ import (
|
|||||||
|
|
||||||
const colSpacing = 1
|
const colSpacing = 1
|
||||||
|
|
||||||
// Calculate per-column width, given total width and number of items
|
// per-column width. 0 == auto width
|
||||||
func calcWidth(width, items int) int {
|
var colWidths = []int{
|
||||||
spacing := colSpacing * items
|
3, // status
|
||||||
return (width - statusWidth - spacing) / items
|
0, // name
|
||||||
|
0, // cid
|
||||||
|
0, // cpu
|
||||||
|
0, // memory
|
||||||
|
0, // net
|
||||||
|
0, // io
|
||||||
|
4, // pids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate per-column width, given total width
|
||||||
|
func calcWidth(width int) int {
|
||||||
|
spacing := colSpacing * len(colWidths)
|
||||||
|
var staticCols int
|
||||||
|
for _, w := range colWidths {
|
||||||
|
width -= w
|
||||||
|
if w == 0 {
|
||||||
|
staticCols += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (width - spacing) / staticCols
|
||||||
}
|
}
|
||||||
|
|
||||||
func centerParText(p *ui.Par) {
|
func centerParText(p *ui.Par) {
|
||||||
|
|||||||
Reference in New Issue
Block a user