mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Added Ports information to the expanded view
This commit is contained in:
committed by
Kenan Rhoton
parent
d81d10ec27
commit
b2165b6a29
@@ -18,6 +18,7 @@ type Expanded struct {
|
||||
Cpu *Cpu
|
||||
Mem *Mem
|
||||
IO *IO
|
||||
Ports *Ports
|
||||
X, Y int
|
||||
Width int
|
||||
}
|
||||
@@ -32,6 +33,7 @@ func NewExpanded(id string) *Expanded {
|
||||
Cpu: NewCpu(),
|
||||
Mem: NewMem(),
|
||||
IO: NewIO(),
|
||||
Ports: NewPorts(),
|
||||
Width: ui.TermWidth(),
|
||||
}
|
||||
}
|
||||
@@ -60,6 +62,7 @@ func (e *Expanded) SetMetrics(m metrics.Metrics) {
|
||||
e.Net.Update(m.NetRx, m.NetTx)
|
||||
e.Mem.Update(int(m.MemUsage), int(m.MemLimit))
|
||||
e.IO.Update(m.IOBytesRead, m.IOBytesWrite)
|
||||
e.Ports.Update(m.PortsExposed, m.PortsOpen)
|
||||
}
|
||||
|
||||
// Return total column height
|
||||
@@ -69,6 +72,7 @@ func (e *Expanded) GetHeight() (h int) {
|
||||
h += e.Cpu.Height
|
||||
h += e.Mem.Height
|
||||
h += e.IO.Height
|
||||
h += e.Ports.Height
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -106,6 +110,7 @@ func (e *Expanded) Buffer() ui.Buffer {
|
||||
buf.Merge(e.Mem.Buffer())
|
||||
buf.Merge(e.Net.Buffer())
|
||||
buf.Merge(e.IO.Buffer())
|
||||
buf.Merge(e.Ports.Buffer())
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -113,6 +118,7 @@ func (e *Expanded) all() []ui.GridBufferer {
|
||||
return []ui.GridBufferer{
|
||||
e.Info,
|
||||
e.Cpu,
|
||||
e.Ports,
|
||||
e.Mem,
|
||||
e.Net,
|
||||
e.IO,
|
||||
|
||||
50
cwidgets/expanded/ports.go
Normal file
50
cwidgets/expanded/ports.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package expanded
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
type Ports struct {
|
||||
*ui.Table
|
||||
Exposed []int
|
||||
Open [][]int
|
||||
}
|
||||
|
||||
func NewPorts() *Ports {
|
||||
t := ui.NewTable()
|
||||
t.BorderLabel = "Ports"
|
||||
t.Height = 4
|
||||
t.Width = colWidth[0]
|
||||
t.FgColor = ui.ThemeAttr("par.text.fg")
|
||||
t.Separator = false
|
||||
p := &Ports{t, nil, nil}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Ports) Update(exposed []int64, open [][]int64) {
|
||||
p.Rows = [][]string{}
|
||||
|
||||
exp_string := ""
|
||||
for i, exp := range exposed {
|
||||
if i == 0 {
|
||||
exp_string = strconv.Itoa(int(exp))
|
||||
} else {
|
||||
exp_string = strings.Join([]string{exp_string, strconv.Itoa(int(exp))}, ", ")
|
||||
}
|
||||
}
|
||||
p.Rows = append(p.Rows, []string{"Exposed: ", exp_string})
|
||||
|
||||
open_string := ""
|
||||
for i, op := range open {
|
||||
ported := strings.Join([]string{strconv.Itoa(int(op[0])), strconv.Itoa(int(op[1]))}, " -> ")
|
||||
if i == 0 {
|
||||
open_string = ported
|
||||
} else {
|
||||
open_string = strings.Join([]string{open_string, ported}, ", ")
|
||||
}
|
||||
}
|
||||
p.Rows = append(p.Rows, []string{"Open: ", open_string})
|
||||
}
|
||||
Reference in New Issue
Block a user