summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-04-27 20:33:41 -0500
committerSean E. Russell <ser@ser1.net>2020-04-27 20:33:41 -0500
commit285d4d02972e5d3e52efa6554fcbb08b42577f7c (patch)
treea06df20b360abdbc011b697e01e7ac9df5022117
parent1e78e6faa096237440e9cbbe254951f6d8588624 (diff)
Go vet/lint cleanups
-rw-r--r--cmd/gotop/main.go45
-rw-r--r--colorschemes/registry_test.go6
-rw-r--r--config.go10
-rw-r--r--devices/devices.go3
-rw-r--r--layout/layout.go5
-rw-r--r--layout/parser.go2
-rw-r--r--logging/logging_test.go4
-rw-r--r--utils/conversions.go3
-rw-r--r--widgets/battery.go14
-rw-r--r--widgets/batterygauge.go16
-rw-r--r--widgets/cpu.go86
-rw-r--r--widgets/disk.go46
-rw-r--r--widgets/help.go11
-rw-r--r--widgets/mem.go22
-rw-r--r--widgets/net.go56
-rw-r--r--widgets/proc.go175
-rw-r--r--widgets/proc_linux.go2
-rw-r--r--widgets/statusbar.go14
-rw-r--r--widgets/temp.go46
19 files changed, 271 insertions, 295 deletions
diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go
index 2458612..291179f 100644
--- a/cmd/gotop/main.go
+++ b/cmd/gotop/main.go
@@ -25,6 +25,7 @@ import (
"github.com/xxxserxxx/gotop/v4/devices"
"github.com/xxxserxxx/gotop/v4/layout"
"github.com/xxxserxxx/gotop/v4/logging"
+ "github.com/xxxserxxx/gotop/v4/widgets"
w "github.com/xxxserxxx/gotop/v4/widgets"
)
@@ -38,7 +39,9 @@ const (
)
var (
- Version = "0.0.0"
+ // Version of the program; set during build from git tags
+ Version = "0.0.0"
+ // BuildDate when the program was compiled; set during build
BuildDate = "Hadean"
conf gotop.Config
help *w.HelpMenu
@@ -104,9 +107,9 @@ func parseArgs(conf *gotop.Config) error {
if *list != "" {
switch *list {
case "layouts":
- fmt.Println(LAYOUTS)
+ fmt.Println(_layouts)
case "colorschemes":
- fmt.Println(COLORSCHEMES)
+ fmt.Println(_colorschemes)
case "paths":
fmt.Println("Loadable colorschemes & layouts, and the config file, are searched for, in order:")
paths := make([]string, 0)
@@ -118,7 +121,7 @@ func parseArgs(conf *gotop.Config) error {
case "devices":
listDevices()
case "keys":
- fmt.Println(KEYS)
+ fmt.Println(widgets.KEYBINDS)
default:
fmt.Printf("Unknown option \"%s\"; try layouts, colorschemes, keys, paths, or devices\n", *list)
os.Exit(1)
@@ -391,7 +394,7 @@ func run() int {
}
return 1
}
- if err := ui.Init(); err != nil {
+ if err = ui.Init(); err != nil {
stderrLogger.Print(err)
return 1
}
@@ -481,40 +484,12 @@ func listDevices() {
}
}
-const KEYS = `Quit: q or <C-c>
-Process navigation:
- k and <Up>: up
- j and <Down>: down
- <C-u>: half page up
- <C-d>: half page down
- <C-b>: full page up
- <C-f>: full page down
- gg and <Home>: jump to top
- G and <End>: jump to bottom
-Process actions:
- <Tab>: toggle process grouping
- dd: kill selected process or group of processes with SIGTERM
- d3: kill selected process or group of processes with SIGQUIT
- d9: kill selected process or group of processes with SIGKILL
-Process sorting
- c: CPU
- m: Mem
- p: PID
-Process filtering:
- /: start editing filter
- (while editing):
- <Enter> accept filter
- <C-c> and <Escape>: clear filter
-CPU and Mem graph scaling:
- h: scale in
- l: scale out
-?: toggles keybind help menu`
-const LAYOUTS = `Built-in layouts:
+const _layouts = `Built-in layouts:
default
minimal
battery
kitchensink`
-const COLORSCHEMES = `Built-in colorschemes:
+const _colorschemes = `Built-in colorschemes:
default
default-dark (for white background)
solarized
diff --git a/colorschemes/registry_test.go b/colorschemes/registry_test.go
index e4216ab..3f288d1 100644
--- a/colorschemes/registry_test.go
+++ b/colorschemes/registry_test.go
@@ -1,6 +1,8 @@
package colorschemes
import (
+ "github.com/shibukawa/configdir"
+ "path/filepath"
"reflect"
"testing"
)
@@ -8,8 +10,10 @@ import (
func TestColorRegistry(t *testing.T) {
colors := []string{"default", "default-dark", "solarized", "solarized16-dark", "solarized16-light", "monokai", "vice"}
zeroCS := Colorscheme{}
+ cd := configdir.New("", "gotop")
+ cd.LocalPath, _ = filepath.Abs(".")
for _, cn := range colors {
- c, e := FromName("", cn)
+ c, e := FromName(cd, cn)
if e != nil {
t.Errorf("unexpected error fetching built-in color %s: %s", cn, e)
}
diff --git a/config.go b/config.go
index fef5478..6a109e0 100644
--- a/config.go
+++ b/config.go
@@ -48,7 +48,7 @@ func NewConfig() Config {
PercpuLoad: true,
TempScale: widgets.Celsius,
Statusbar: false,
- NetInterface: widgets.NET_INTERFACE_ALL,
+ NetInterface: widgets.NetInterfaceAll,
MaxLogSize: 5000000,
Layout: "default",
ExtensionVars: make(map[string]string),
@@ -169,16 +169,16 @@ func load(in io.Reader, conf *Config) error {
return nil
}
-func (c *Config) Write() (string, error) {
+func (conf *Config) Write() (string, error) {
cfn := "gotop.conf"
- ds := c.ConfigDir.QueryFolders(configdir.Global)
+ ds := conf.ConfigDir.QueryFolders(configdir.Global)
if len(ds) == 0 {
- ds = c.ConfigDir.QueryFolders(configdir.Local)
+ ds = conf.ConfigDir.QueryFolders(configdir.Local)
if len(ds) == 0 {
return "", fmt.Errorf("error locating config folders")
}
}
- marshalled := marshal(c)
+ marshalled := marshal(conf)
err := ds[0].WriteFile(cfn, marshalled)
if err != nil {
return "", err
diff --git a/devices/devices.go b/devices/devices.go
index 5923cb6..a804fab 100644
--- a/devices/devices.go
+++ b/devices/devices.go
@@ -78,7 +78,6 @@ func RegisterDeviceList(typ string, all func() []string, def func() []string) {
func Devices(domain string, all bool) []string {
if all {
return _devs[domain]
- } else {
- return _defaults[domain]
}
+ return _defaults[domain]
}
diff --git a/layout/layout.go b/layout/layout.go
index bc0ff2d..b4343b4 100644
--- a/layout/layout.go
+++ b/layout/layout.go
@@ -1,4 +1,3 @@
-// Copyright 2020 The gotop Authors Licensed under terms of the LICENSE file in this repository.
package layout
import (
@@ -165,7 +164,7 @@ func makeWidget(c gotop.Config, widRule widgetRule) interface{} {
dw := widgets.NewDiskWidget()
w = dw
case "cpu":
- cpu := widgets.NewCpuWidget(c.UpdateInterval, c.GraphHorizontalScale, c.AverageLoad, c.PercpuLoad)
+ cpu := widgets.NewCPUWidget(c.UpdateInterval, c.GraphHorizontalScale, c.AverageLoad, c.PercpuLoad)
assignColors(cpu.Data, c.Colorscheme.CPULines, cpu.LineColors)
w = cpu
case "mem":
@@ -228,7 +227,7 @@ func assignColors(data map[string][]float64, colors []int, assign map[string]ui.
func countNumRows(rs [][]widgetRule) int {
var ttl int
for len(rs) > 0 {
- ttl += 1
+ ttl++
line := rs[0]
h := 1
for _, c := range line {
diff --git a/layout/parser.go b/layout/parser.go
index f35171e..b747eae 100644
--- a/layout/parser.go
+++ b/layout/parser.go
@@ -111,7 +111,7 @@ func ParseLayout(i io.Reader) layout {
}
weightTotal += weight
} else {
- weightTotal += 1
+ weightTotal++
}
row = append(row, wr)
}
diff --git a/logging/logging_test.go b/logging/logging_test.go
index a1ac3d4..1ea7484 100644
--- a/logging/logging_test.go
+++ b/logging/logging_test.go
@@ -17,8 +17,6 @@ func TestLogging(t *testing.T) {
defer os.RemoveAll(path)
c := gotop.Config{
MaxLogSize: 300,
- LogDir: path,
- LogFile: "errors.log",
}
wc, err := New(c)
assert.NoError(t, err)
@@ -27,7 +25,7 @@ func TestLogging(t *testing.T) {
}
defer wc.Close()
ds := make([]byte, 100)
- for i, _ := range ds {
+ for i := range ds {
ds[i] = 'x'
}
diff --git a/utils/conversions.go b/utils/conversions.go
index 5d86ac4..3098d1f 100644
--- a/utils/conversions.go
+++ b/utils/conversions.go
@@ -7,7 +7,6 @@ import (
func ConvertLocalizedString(s string) string {
if strings.ContainsAny(s, ",") {
return strings.Replace(s, ",", ".", 1)
- } else {
- return s
}
+ return s
}
diff --git a/widgets/battery.go b/widgets/battery.go
index 4e813e7..7167668 100644
--- a/widgets/battery.go
+++ b/widgets/battery.go
@@ -62,7 +62,7 @@ func (b *BatteryWidget) EnableMetric() {
}
}
-func makeId(i int) string {
+func makeID(i int) string {
return "Batt" + strconv.Itoa(i)
}
@@ -70,7 +70,7 @@ func (b *BatteryWidget) Scale(i int) {
b.LineGraph.HorizontalScale = i
}
-func (self *BatteryWidget) update() {
+func (b *BatteryWidget) update() {
batteries, err := battery.GetAll()
if err != nil {
switch errt := err.(type) {
@@ -94,13 +94,13 @@ func (self *BatteryWidget) update() {
}
}
for i, battery := range batteries {
- id := makeId(i)
+ id := makeID(i)
perc := battery.Current / battery.Full
percentFull := math.Abs(perc) * 100.0
- self.Data[id] = append(self.Data[id], percentFull)
- self.Labels[id] = fmt.Sprintf("%3.0f%% %.0f/%.0f", percentFull, math.Abs(battery.Current), math.Abs(battery.Full))
- if self.metric != nil {
- self.metric[i].Set(perc)
+ b.Data[id] = append(b.Data[id], percentFull)
+ b.Labels[id] = fmt.Sprintf("%3.0f%% %.0f/%.0f", percentFull, math.Abs(battery.Current), math.Abs(battery.Full))
+ if b.metric != nil {
+ b.metric[i].Set(perc)
}
}
}
diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go
index a379a84..45fec1c 100644
--- a/widgets/batterygauge.go
+++ b/widgets/batterygauge.go
@@ -9,16 +9,16 @@ import (
"github.com/distatus/battery"
"github.com/prometheus/client_golang/prometheus"
- . "github.com/xxxserxxx/gotop/v4/termui"
+ "github.com/xxxserxxx/gotop/v4/termui"
)
type BatteryGauge struct {
- *Gauge
+ *termui.Gauge
metric prometheus.Gauge
}
func NewBatteryGauge() *BatteryGauge {
- self := &BatteryGauge{Gauge: NewGauge()}
+ self := &BatteryGauge{Gauge: termui.NewGauge()}
self.Title = " Power Level "
self.update()
@@ -56,7 +56,7 @@ func (b *BatteryGauge) EnableMetric() {
}
}
-func (self *BatteryGauge) update() {
+func (b *BatteryGauge) update() {
bats, err := battery.GetAll()
if err != nil {
log.Printf("error setting up batteries: %v", err)
@@ -78,9 +78,9 @@ func (self *BatteryGauge) update() {
}
tn := (mx - cu) / rate
d, _ := time.ParseDuration(fmt.Sprintf("%fh", tn))
- self.Percent = int((cu / mx) * 100.0)
- self.Label = fmt.Sprintf(charging, self.Percent, d.Truncate(time.Minute))
- if self.metric != nil {
- self.metric.Set(cu / mx)
+ b.Percent = int((cu / mx) * 100.0)
+ b.Label = fmt.Sprintf(charging, b.Percent, d.Truncate(time.Minute))
+ if b.metric != nil {
+ b.metric.Set(cu / mx)
}
}
diff --git a/widgets/cpu.go b/widgets/cpu.go
index c48273e..03346bf 100644
--- a/widgets/cpu.go
+++ b/widgets/cpu.go
@@ -12,11 +12,11 @@ import (
ui "github.com/xxxserxxx/gotop/v4/termui"
)
-type CpuWidget struct {
+type CPUWidget struct {
*ui.LineGraph
- CpuCount int
+ CPUCount int
ShowAverageLoad bool
- ShowPerCpuLoad bool
+ ShowPerCPULoad bool
updateInterval time.Duration
updateLock sync.Mutex
metric map[string]prometheus.Gauge
@@ -24,20 +24,20 @@ type CpuWidget struct {
var cpuLabels []string
-func NewCpuWidget(updateInterval time.Duration, horizontalScale int, showAverageLoad bool, showPerCpuLoad bool) *CpuWidget {
- self := &CpuWidget{
+func NewCPUWidget(updateInterval time.Duration, horizontalScale int, showAverageLoad bool, showPerCPULoad bool) *CPUWidget {
+ self := &CPUWidget{
LineGraph: ui.NewLineGraph(),
- CpuCount: len(cpuLabels),
+ CPUCount: len(cpuLabels),
updateInterval: updateInterval,
ShowAverageLoad: showAverageLoad,
- ShowPerCpuLoad: showPerCpuLoad,
+ ShowPerCPULoad: showPerCPULoad,
}
self.Title = " CPU Usage "
self.HorizontalScale = horizontalScale
- if !(self.ShowAverageLoad || self.ShowPerCpuLoad) {
- if self.CpuCount <= 8 {
- self.ShowPerCpuLoad = true
+ if !(self.ShowAverageLoad || self.ShowPerCPULoad) {
+ if self.CPUCount <= 8 {
+ self.ShowPerCPULoad = true
} else {
self.ShowAverageLoad = true
}
@@ -47,9 +47,9 @@ func NewCpuWidget(updateInterval time.Duration, horizontalScale int, showAverage
self.Data["AVRG"] = []float64{0}
}
- if self.ShowPerCpuLoad {
+ if self.ShowPerCPULoad {
cpus := make(map[string]int)
- devices.UpdateCPU(cpus, self.updateInterval, self.ShowPerCpuLoad)
+ devices.UpdateCPU(cpus, self.updateInterval, self.ShowPerCPULoad)
for k, v := range cpus {
self.Data[k] = []float64{float64(v)}
}
@@ -66,17 +66,17 @@ func NewCpuWidget(updateInterval time.Duration, horizontalScale int, showAverage
return self
}
-func (self *CpuWidget) EnableMetric() {
- if self.ShowAverageLoad {
- self.metric = make(map[string]prometheus.Gauge)
- self.metric["AVRG"] = prometheus.NewGauge(prometheus.GaugeOpts{
+func (cpu *CPUWidget) EnableMetric() {
+ if cpu.ShowAverageLoad {
+ cpu.metric = make(map[string]prometheus.Gauge)
+ cpu.metric["AVRG"] = prometheus.NewGauge(prometheus.GaugeOpts{
Subsystem: "cpu",
Name: "avg",
})
} else {
cpus := make(map[string]int)
- devices.UpdateCPU(cpus, self.updateInterval, self.ShowPerCpuLoad)
- self.metric = make(map[string]prometheus.Gauge)
+ devices.UpdateCPU(cpus, cpu.updateInterval, cpu.ShowPerCPULoad)
+ cpu.metric = make(map[string]prometheus.Gauge)
for key, perc := range cpus {
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "gotop",
@@ -85,53 +85,53 @@ func (self *CpuWidget) EnableMetric() {
})
gauge.Set(float64(perc))
prometheus.MustRegister(gauge)
- self.metric[key] = gauge
+ cpu.metric[key] = gauge
}
}
}
-func (b *CpuWidget) Scale(i int) {
- b.LineGraph.HorizontalScale = i
+func (cpu *CPUWidget) Scale(i int) {
+ cpu.LineGraph.HorizontalScale = i
}
-func (self *CpuWidget) update() {
- if self.ShowAverageLoad {
+func (cpu *CPUWidget) update() {
+ if cpu.ShowAverageLoad {
go func() {
cpus := make(map[string]int)
- devices.UpdateCPU(cpus, self.updateInterval, false)
- self.Lock()
- defer self.Unlock()
- self.updateLock.Lock()
- defer self.updateLock.Unlock()
+ devices.UpdateCPU(cpus, cpu.updateInterval, false)
+ cpu.Lock()
+ defer cpu.Unlock()
+ cpu.updateLock.Lock()
+ defer cpu.updateLock.Unlock()
var val float64
for _, v := range cpus {
val = float64(v)
break
}
- self.Data["AVRG"] = append(self.Data["AVRG"], val)
- self.Labels["AVRG"] = fmt.Sprintf("%3.0f%%", val)
- if self.metric != nil {
- self.metric["AVRG"].Set(val)
+ cpu.Data["AVRG"] = append(cpu.Data["AVRG"], val)
+ cpu.Labels["AVRG"] = fmt.Sprintf("%3.0f%%", val)
+ if cpu.metric != nil {
+ cpu.metric["AVRG"].Set(val)
}
}()
}
- if self.ShowPerCpuLoad {
+ if cpu.ShowPerCPULoad {
go func() {
cpus := make(map[string]int)
- devices.UpdateCPU(cpus, self.updateInterval, true)
- self.Lock()
- defer self.Unlock()
- self.updateLock.Lock()
- defer self.updateLock.Unlock()
+ devices.UpdateCPU(cpus, cpu.updateInterval, true)
+ cpu.Lock()
+ defer cpu.Unlock()
+ cpu.updateLock.Lock()
+ defer cpu.updateLock.Unlock()
for key, percent := range cpus {
- self.Data[key] = append(self.Data[key], float64(percent))
- self.Labels[key] = fmt.Sprintf("%d%%", percent)
- if self.metric != nil {
- if self.metric[key] == nil {
+ cpu.Data[key] = append(cpu.Data[key], float64(percent))
+ cpu.Labels[key] = fmt.Sprintf("%d%%", percent)
+ if cpu.metric != nil {
+ if cpu.metric[key] == nil {
log.Printf("no metrics for %s", key)
} else {
- self.metric[key].Set(float64(percent))
+ cpu.metric[key].Set(float64(percent))
}
}
}
diff --git a/widgets/disk.go b/widgets/disk.go
index 54f4a33..fb77ace 100644
--- a/widgets/disk.go
+++ b/widgets/disk.go
@@ -64,9 +64,9 @@ func NewDiskWidget() *DiskWidget {
return self
}
-func (self *DiskWidget) EnableMetric() {
- self.metric = make(map[string]prometheus.Gauge)
- for key, part := range self.Partitions {
+func (disk *DiskWidget) EnableMetric() {
+ disk.metric = make(map[string]prometheus.Gauge)
+ for key, part := range disk.Partitions {
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "gotop",
Subsystem: "disk",
@@ -75,11 +75,11 @@ func (self *DiskWidget) EnableMetric() {
})
gauge.Set(float64(part.UsedPercent) / 100.0)
prometheus.MustRegister(gauge)
- self.metric[key] = gauge
+ disk.metric[key] = gauge
}
}
-func (self *DiskWidget) update() {
+func (disk *DiskWidget) update() {
partitions, err := psDisk.Partitions(false)
if err != nil {
log.Printf("failed to get disk partitions from gopsutil: %v", err)
@@ -97,8 +97,8 @@ func (self *DiskWidget) update() {
continue
}
// check if partition doesn't already exist in our list
- if _, ok := self.Partitions[partition.Device]; !ok {
- self.Partitions[partition.Device] = &Partition{
+ if _, ok := disk.Partitions[partition.Device]; !ok {
+ disk.Partitions[partition.Device] = &Partition{
Device: partition.Device,
MountPoint: partition.Mountpoint,
}
@@ -107,7 +107,7 @@ func (self *DiskWidget) update() {
// delete a partition if it no longer exists
toDelete := []string{}
- for device := range self.Partitions {
+ for device := range disk.Partitions {
exists := false
for _, partition := range partitions {
if device == partition.Device {
@@ -120,11 +120,11 @@ func (self *DiskWidget) update() {
}
}
for _, device := range toDelete {
- delete(self.Partitions, device)
+ delete(disk.Partitions, device)
}
// updates partition info. We add 0.5 to all values to make sure the truncation rounds
- for _, partition := range self.Partitions {
+ for _, partition := range disk.Partitions {
usage, err := psDisk.Usage(partition.MountPoint)
if err != nil {
log.Printf("failed to get partition usage statistics from gopsutil: %v. partition: %v", err, partition)
@@ -160,27 +160,27 @@ func (self *DiskWidget) update() {
// converts self.Partitions into self.Rows which is a [][]String
sortedPartitions := []string{}
- for seriesName := range self.Partitions {
+ for seriesName := range disk.Partitions {
sortedPartitions = append(sortedPartitions, seriesName)
}
sort.Strings(sortedPartitions)
- self.Rows = make([][]string, len(self.Partitions))
+ disk.Rows = make([][]string, len(disk.Partitions))
for i, key := range sortedPartitions {
- partition := self.Partitions[key]
- self.Rows[i] = make([]string, 6)
- self.Rows[i][0] = strings.Replace(strings.Replace(partition.Device, "/dev/", "", -1), "mapper/", "", -1)
- self.Rows[i][1] = partition.MountPoint
- self.Rows[i][2] = fmt.Sprintf("%d%%", partition.UsedPercent)
- self.Rows[i][3] = partition.Free
- self.Rows[i][4] = partition.BytesReadRecently
- self.Rows[i][5] = partition.BytesWrittenRecently
- if self.metric != nil {
- if self.metric[key] == nil {
+ partition := disk.Partitions[key]
+ disk.Rows[i] = make([]string, 6)
+ disk.Rows[i][0] = strings.Replace(strings.Replace(partition.Device, "/dev/", "", -1), "mapper/", "", -1)
+ disk.Rows[i][1] = partition.MountPoint
+ disk.Rows[i][2] = fmt.Sprintf("%d%%", partition.UsedPercent)
+ disk.Rows[i][3] = partition.Free
+ disk.Rows[i][4] = partition.BytesReadRecently
+ disk.Rows[i][5] = partition.BytesWrittenRecently
+ if disk.metric != nil {
+ if disk.metric[key] == nil {
log.Printf("ERROR: missing metric %s", key)
} else {
- self.metric[key].Set(float64(partition.UsedPercent) / 100.0)
+ disk.metric[key].Set(float64(partition.UsedPercent) / 100.0)
}
}
}
diff --git a/widgets/help.go b/widgets/help.go
index 012ca9d..a2c38e4 100644
--- a/widgets/help.go
+++ b/widgets/help.go
@@ -7,6 +7,7 @@ import (
ui "github.com/gizak/termui/v3"
)
+// KEYBINDS is the help text for the in-program shortcuts
const KEYBINDS = `
Quit: q or <C-c>
@@ -55,7 +56,7 @@ func NewHelpMenu() *HelpMenu {
}
}
-func (self *HelpMenu) Resize(termWidth, termHeight int) {
+func (help *HelpMenu) Resize(termWidth, termHeight int) {
textWidth := 53
for _, line := range strings.Split(KEYBINDS, "\n") {
if textWidth < len(line) {
@@ -66,17 +67,17 @@ func (self *HelpMenu) Resize(termWidth, termHeight int) {
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
- self.Block.SetRect(x, y, textWidth+x, textHeight+y)
+ help.Block.SetRect(x, y, textWidth+x, textHeight+y)
}
-func (self *HelpMenu) Draw(buf *ui.Buffer) {
- self.Block.Draw(buf)
+func (help *HelpMenu) Draw(buf *ui.Buffer) {
+ help.Block.Draw(buf)
for y, line := range strings.Split(KEYBINDS, "\n") {
for x, rune := range line {
buf.SetCell(
ui.NewCell(rune, ui.Theme.Default),
- image.Pt(self.Inner.Min.X+x, self.Inner.Min.Y+y-1),
+ image.Pt(help.Inner.Min.X+x, help.Inner.Min.Y+y-1),
)
}
}
diff --git a/widgets/mem.go b/widgets/mem.go
index 4bf8550..6b5d326 100644
--- a/widgets/mem.go
+++ b/widgets/mem.go
@@ -48,30 +48,30 @@ func NewMemWidget(updateInterval time.Duration, horizontalScale int) *MemWidget
return self
}
-func (b *MemWidget) EnableMetric() {
- b.metrics = make(map[string]prometheus.Gauge)
+func (mem *MemWidget) EnableMetric() {
+ mem.metrics = make(map[string]prometheus.Gauge)
mems := make(map[string]devices.MemoryInfo)
devices.UpdateMem(mems)
- for l, mem := range mems {
- b.metrics[l] = prometheus.NewGauge(prometheus.GaugeOpts{
+ for l, m := range mems {
+ mem.metrics[l] = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "gotop",
Subsystem: "memory",
Name: l,
})
- b.metrics[l].Set(mem.UsedPercent)
- prometheus.MustRegister(b.metrics[l])
+ mem.metrics[l].Set(m.UsedPercent)
+ prometheus.MustRegister(mem.metrics[l])
}
}
-func (b *MemWidget) Scale(i int) {
- b.LineGraph.HorizontalScale = i
+func (mem *MemWidget) Scale(i int) {
+ mem.LineGraph.HorizontalScale = i
}
-func (self *MemWidget) renderMemInfo(line string, memoryInfo devices.MemoryInfo) {
- self.Data[line] = append(self.Data[line], memoryInfo.UsedPercent)
+func (mem *MemWidget) renderMemInfo(line string, memoryInfo devices.MemoryInfo) {
+ mem.Data[line] = append(mem.Data[line], memoryInfo.UsedPercent)
memoryTotalBytes, memoryTotalMagnitude := utils.ConvertBytes(memoryInfo.Total)
memoryUsedBytes, memoryUsedMagnitude := utils.ConvertBytes(memoryInfo.Used)
- self.Labels[line] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s",
+ mem.Labels[line] = fmt.Sprintf("%3.0f%% %5.1f%s/%.0f%s",
memoryInfo.UsedPercent,
memoryUsedBytes,
memoryUsedMagnitude,
diff --git a/widgets/net.go b/widgets/net.go
index f851454..9cd4211 100644
--- a/widgets/net.go
+++ b/widgets/net.go
@@ -14,8 +14,10 @@ import (
)
const (
- NET_INTERFACE_ALL = "all"
- NET_INTERFACE_VPN = "tun0"
+ // NetInterfaceAll enables all network interfaces
+ NetInterfaceAll = "all"
+ // NetInterfaceVpn is the VPN interface
+ NetInterfaceVpn = "tun0"
)
type NetWidget struct {
@@ -63,23 +65,23 @@ func NewNetWidget(netInterface string) *NetWidget {
return self
}
-func (b *NetWidget) EnableMetric() {
- b.recvMetric = prometheus.NewCounter(prometheus.CounterOpts{
+func (net *NetWidget) EnableMetric() {
+ net.recvMetric = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "gotop",
Subsystem: "net",
Name: "recv",
})
- prometheus.MustRegister(b.recvMetric)
+ prometheus.MustRegister(net.recvMetric)
- b.sentMetric = prometheus.NewCounter(prometheus.CounterOpts{
+ net.sentMetric = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "gotop",
Subsystem: "net",
Name: "sent",
})
- prometheus.MustRegister(b.sentMetric)
+ prometheus.MustRegister(net.sentMetric)
}
-func (self *NetWidget) update() {
+func (net *NetWidget) update() {
interfaces, err := psNet.IOCounters(true)
if err != nil {
log.Printf("failed to get network activity from gopsutil: %v", err)
@@ -90,15 +92,15 @@ func (self *NetWidget) update() {
var totalBytesSent uint64
interfaceMap := make(map[string]bool)
// Default behaviour
- interfaceMap[NET_INTERFACE_ALL] = true
- interfaceMap[NET_INTERFACE_VPN] = false
+ interfaceMap[NetInterfaceAll] = true
+ interfaceMap[NetInterfaceVpn] = false
// Build a map with wanted status for each interfaces.
- for _, iface := range self.NetInterface {
+ for _, iface := range net.NetInterface {
if strings.HasPrefix(iface, "!") {
interfaceMap[strings.TrimPrefix(iface, "!")] = false
} else {
// if we specify a wanted interface, remove capture on all.
- delete(interfaceMap, NET_INTERFACE_ALL)
+ delete(interfaceMap, NetInterfaceAll)
interfaceMap[iface] = true
}
}
@@ -109,7 +111,7 @@ func (self *NetWidget) update() {
totalBytesSent += _interface.BytesSent
} else if ok { // Present but unwanted
continue
- } else if interfaceMap[NET_INTERFACE_ALL] { // Capture other
+ } else if interfaceMap[NetInterfaceAll] { // Capture other
totalBytesRecv += _interface.BytesRecv
totalBytesSent += _interface.BytesSent
}
@@ -118,9 +120,9 @@ func (self *NetWidget) update() {
var recentBytesRecv uint64
var recentBytesSent uint64
- if self.totalBytesRecv != 0 { // if this isn't the first update
- recentBytesRecv = totalBytesRecv - self.totalBytesRecv
- recentBytesSent = totalBytesSent - self.totalBytesSent
+ if net.totalBytesRecv != 0 { // if this isn't the first update
+ recentBytesRecv = totalBytesRecv - net.totalBytesRecv
+ recentBytesSent = totalBytesSent - net.totalBytesSent
if int(recentBytesRecv) < 0 {
log.Printf("error: negative value for recently received network data from gopsutil. recentBytesRecv: %v", recentBytesRecv)
@@ -133,20 +135,20 @@ func (self *NetWidget) update() {
recentBytesSent = 0
}
- self.Lines[0].Data = append(self.Lines[0].Data, int(recentBytesRecv))
- self.Lines[1].Data = append(self.Lines[1].Data, int(recentBytesSent))
- if self.sentMetric != nil {
- self.sentMetric.Add(float64(recentBytesSent))
- self.recvMetric.Add(float64(recentBytesRecv))
+ net.Lines[0].Data = append(net.Lines[0].Data, int(recentBytesRecv))
+ net.Lines[1].Data = append(net.Lines[1].Data, int(recentBytesSent))
+ if net.sentMetric != nil {
+ net.sentMetric.Add(float64(recentBytesSent))
+ net.recvMetric.Add(float64(recentBytesRecv))
}
}
// used in later calls to update
- self.totalBytesRecv = totalBytesRecv
- self.totalBytesSent = totalBytesSent
+ net.totalBytesRecv = totalBytesRecv
+ net.totalBytesSent = totalBytesSent
rx, tx := "RX/s", "TX/s"
- if self.Mbps {
+ if net.Mbps {
rx, tx = "mbps", "mbps"
}
format := " %s: %9.1f %2s/s"
@@ -163,13 +165,13 @@ func (self *NetWidget) update() {
}
totalConverted, unitTotal := utils.ConvertBytes(total)
- if self.Mbps {
+ if net.Mbps {
recentConverted, unitRecent, format = float64(recent)*0.000008, "", " %s: %11.3f %2s"
} else {
recentConverted, unitRecent = utils.ConvertBytes(recent)
}
- self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConverted, unitTotal)
- self.Lines[i].Title2 = fmt.Sprintf(format, rate, recentConverted, unitRecent)
+ net.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConverted, unitTotal)
+ net.Lines[i].Title2 = fmt.Sprintf(format, rate, recentConverted, unitRecent)
}
}
diff --git a/widgets/proc.go b/widgets/proc.go
index c691755..f47f646 100644
--- a/widgets/proc.go
+++ b/widgets/proc.go
@@ -17,14 +17,13 @@ import (
)
const (
- UP_ARROW = "▲"
- DOWN_ARROW = "▼"
+ _downArrow = "▼"
)
type ProcSortMethod string
const (
- ProcSortCpu ProcSortMethod = "c"
+ ProcSortCPU ProcSortMethod = "c"
ProcSortMem = "m"
ProcSortPid = "p"
)
@@ -33,7 +32,7 @@ type Proc struct {
Pid int
CommandName string
FullCommand string
- Cpu float64
+ CPU float64
Mem float64
}
@@ -58,7 +57,7 @@ func NewProcWidget() *ProcWidget {
Table: ui.NewTable(),
updateInterval: time.Second,
cpuCount: cpuCount,
- sortMethod: ProcSortCpu,
+ sortMethod: ProcSortCPU,
showGroupedProcs: true,
filter: "",
}
@@ -100,42 +99,42 @@ func NewProcWidget() *ProcWidget {
return self
}
-func (p *ProcWidget) EnableMetric() {
+func (proc *ProcWidget) EnableMetric() {
// There's (currently) no metric for this
}
-func (self *ProcWidget) SetEditingFilter(editing bool) {
- self.entry.SetEditing(editing)
+func (proc *ProcWidget) SetEditingFilter(editing bool) {
+ proc.entry.SetEditing(editing)
}
-func (self *ProcWidget) HandleEvent(e tui.Event) bool {
- return self.entry.HandleEvent(e)
+func (proc *ProcWidget) HandleEvent(e tui.Event) bool {
+ return proc.entry.HandleEvent(e)
}
-func (self *ProcWidget) SetRect(x1, y1, x2, y2 int) {
- self.Table.SetRect(x1, y1, x2, y2)
- self.entry.SetRe