From ee1c57c6fe364457c2461c8f18848480779712bb Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Wed, 16 May 2018 14:38:28 -0700 Subject: [PATCH] Show process args when ungrouped on unix --- Gopkg.lock | 2 +- src/widgets/proc.go | 15 +++++++++++---- src/widgets/proc_unix.go | 3 ++- src/widgets/proc_windows.go | 3 +++ vendor/github.com/cjbassi/termui/colors.go | 1 + vendor/github.com/cjbassi/termui/table.go | 6 +++++- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 0cc5818..1486eef 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -17,7 +17,7 @@ branch = "master" name = "github.com/cjbassi/termui" packages = ["."] - revision = "75525ee19c41f52324024b7a2bf31edcd1428494" + revision = "50e37fc8a80ca08ddca62be4537c7d49261994a3" [[projects]] branch = "master" diff --git a/src/widgets/proc.go b/src/widgets/proc.go index 47e50d1..8a47709 100644 --- a/src/widgets/proc.go +++ b/src/widgets/proc.go @@ -22,6 +22,7 @@ type Process struct { Command string CPU float64 Mem float64 + Args string } type Proc struct { @@ -100,7 +101,7 @@ func (self *Proc) Sort() { self.Header[3] += DOWN } - self.Rows = FieldsToStrings(*processes) + self.Rows = FieldsToStrings(*processes, self.group) } // ColResize overrides the default ColResize in the termui table. @@ -220,6 +221,7 @@ func Group(P []Process) []Process { val.Command, val.CPU + process.CPU, val.Mem + process.Mem, + "", } } else { groupedP[process.Command] = Process{ @@ -227,6 +229,7 @@ func Group(P []Process) []Process { process.Command, process.CPU, process.Mem, + "", } } } @@ -242,14 +245,18 @@ func Group(P []Process) []Process { } // FieldsToStrings converts a []Process to a [][]string -func FieldsToStrings(P []Process) [][]string { +func FieldsToStrings(P []Process, grouped bool) [][]string { strings := make([][]string, len(P)) for i, p := range P { strings[i] = make([]string, 4) strings[i][0] = strconv.Itoa(int(p.PID)) - strings[i][1] = p.Command + if grouped { + strings[i][1] = p.Command + } else { + strings[i][1] = p.Args + } strings[i][2] = fmt.Sprintf("%4s", strconv.FormatFloat(p.CPU, 'f', 1, 64)) - strings[i][3] = fmt.Sprintf("%4s", strconv.FormatFloat(float64(p.Mem), 'f', 1, 32)) + strings[i][3] = fmt.Sprintf("%4s", strconv.FormatFloat(float64(p.Mem), 'f', 1, 64)) } return strings } diff --git a/src/widgets/proc_unix.go b/src/widgets/proc_unix.go index f49b6e2..2253aca 100644 --- a/src/widgets/proc_unix.go +++ b/src/widgets/proc_unix.go @@ -22,7 +22,7 @@ func (self *Proc) update() { } func Processes() []Process { - output, _ := exec.Command("ps", "--no-headers", "-acxo", "pid,comm,pcpu,pmem").Output() + output, _ := exec.Command("ps", "--no-headers", "-axo", "pid,comm,pcpu,pmem,args").Output() strOutput := strings.TrimSpace(string(output)) processes := []Process{} for _, line := range strings.Split(strOutput, "\n") { @@ -35,6 +35,7 @@ func Processes() []Process { Command: split[1], CPU: cpu, Mem: mem, + Args: strings.Join(split[4:], " "), } processes = append(processes, process) } diff --git a/src/widgets/proc_windows.go b/src/widgets/proc_windows.go index e59ea27..4b362db 100644 --- a/src/widgets/proc_windows.go +++ b/src/widgets/proc_windows.go @@ -18,6 +18,9 @@ func (self *Proc) update() { command, cpu / self.cpuCount, float64(mem), + // getting command args using gopsutil's Cmdline and CmdlineSlice wasn't + // working the last time I tried it, so we're just reusing 'command' + command, } } diff --git a/vendor/github.com/cjbassi/termui/colors.go b/vendor/github.com/cjbassi/termui/colors.go index 7913a67..b0ef8ba 100644 --- a/vendor/github.com/cjbassi/termui/colors.go +++ b/vendor/github.com/cjbassi/termui/colors.go @@ -1,6 +1,7 @@ package termui // Color is an integer in the range -1 to 255. +// -1 is clear, while 0-255 are xterm 256 colors. type Color int // ColorDefault = clear diff --git a/vendor/github.com/cjbassi/termui/table.go b/vendor/github.com/cjbassi/termui/table.go index 816363a..b9b7bfb 100644 --- a/vendor/github.com/cjbassi/termui/table.go +++ b/vendor/github.com/cjbassi/termui/table.go @@ -106,7 +106,11 @@ func (self *Table) Buffer() *Buffer { if width == 0 { continue } - r := MaxString(row[i], self.X-self.CellXPos[i]) + width = self.X - self.CellXPos[i] + if len(self.CellXPos) > i+1 { + width -= self.X - self.CellXPos[i+1] + } + r := MaxString(row[i], width) buf.SetString(self.CellXPos[i], y, r, self.Fg, bg) } }