summaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-11-23 14:58:32 -0600
committerSean E. Russell <ser@ser1.net>2020-11-23 14:58:32 -0600
commitdaf5916fde35c7ae2a69fc45a32f9c684d88fe2b (patch)
tree2090650c190b4a517d6d1f4da8fde1cb3b2c2563 /widgets
parent72cde0545887f98e58423c1495327276daa202b5 (diff)
parentedf0c2a3a8edd43a685ef91c2e3f9f3ea7d5bc23 (diff)
Resolves merge conflicts
Diffstat (limited to 'widgets')
-rw-r--r--widgets/battery.go12
-rw-r--r--widgets/batterygauge.go2
-rw-r--r--widgets/cpu.go2
-rw-r--r--widgets/disk.go11
-rw-r--r--widgets/help.go51
-rw-r--r--widgets/mem.go2
-rw-r--r--widgets/net.go14
-rw-r--r--widgets/proc.go17
-rw-r--r--widgets/proc_freebsd.go13
-rw-r--r--widgets/proc_linux.go8
-rw-r--r--widgets/proc_other.go8
-rw-r--r--widgets/proc_windows.go22
-rw-r--r--widgets/statusbar.go2
-rw-r--r--widgets/temp.go2
14 files changed, 77 insertions, 89 deletions
diff --git a/widgets/battery.go b/widgets/battery.go
index 77b102f..d8334bb 100644
--- a/widgets/battery.go
+++ b/widgets/battery.go
@@ -23,7 +23,7 @@ func NewBatteryWidget(horizontalScale int) *BatteryWidget {
LineGraph: ui.NewLineGraph(),
updateInterval: time.Minute,
}
- self.Title = " Battery Status "
+ self.Title = tr.Value("widget.label.battery")
self.HorizontalScale = horizontalScale
// intentional duplicate
@@ -45,7 +45,7 @@ func NewBatteryWidget(horizontalScale int) *BatteryWidget {
func (b *BatteryWidget) EnableMetric() {
bats, err := battery.GetAll()
if err != nil {
- log.Printf("error setting up metrics: %v", err)
+ log.Printf(tr.Value("error.metricsetup", "batt", err.Error()))
return
}
for i, _ := range bats {
@@ -60,7 +60,7 @@ func (b *BatteryWidget) EnableMetric() {
}
func makeID(i int) string {
- return "Batt" + strconv.Itoa(i)
+ return tr.Value("widget.label.batt") + strconv.Itoa(i)
}
func (b *BatteryWidget) Scale(i int) {
@@ -72,7 +72,7 @@ func (b *BatteryWidget) update() {
if err != nil {
switch errt := err.(type) {
case battery.ErrFatal:
- log.Printf("fatal error fetching battery info: %v", err)
+ log.Printf(tr.Value("error.fatalfetch", "batt", err.Error()))
return
case battery.Errors:
batts := make([]*battery.Battery, 0)
@@ -80,11 +80,11 @@ func (b *BatteryWidget) update() {
if e == nil {
batts = append(batts, batteries[i])
} else {
- log.Printf("recoverable error fetching battery info; skipping battery: %v", e)
+ log.Printf(tr.Value("error.recovfetch"), "batt", e.Error())
}
}
if len(batts) < 1 {
- log.Print("no usable batteries found")
+ log.Print(tr.Value("error.nodevfound", "batt"))
return
}
batteries = batts
diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go
index 02a8866..20d92d4 100644
--- a/widgets/batterygauge.go
+++ b/widgets/batterygauge.go
@@ -18,7 +18,7 @@ type BatteryGauge struct {
func NewBatteryGauge() *BatteryGauge {
self := &BatteryGauge{Gauge: termui.NewGauge()}
- self.Title = " Power Level "
+ self.Title = tr.Value("widget.label.gauge")
self.update()
diff --git a/widgets/cpu.go b/widgets/cpu.go
index 2924884..9983a10 100644
--- a/widgets/cpu.go
+++ b/widgets/cpu.go
@@ -35,7 +35,7 @@ func NewCPUWidget(updateInterval time.Duration, horizontalScale int, showAverage
average: ewma.NewMovingAverage(),
}
self.LabelStyles[AVRG] = termui.ModifierBold
- self.Title = " CPU Usage "
+ self.Title = tr.Value("widget.label.cpu")
self.HorizontalScale = horizontalScale
if !(self.ShowAverageLoad || self.ShowPerCPULoad) {
diff --git a/widgets/disk.go b/widgets/disk.go
index f1921fd..9df3c3b 100644
--- a/widgets/disk.go
+++ b/widgets/disk.go
@@ -37,8 +37,9 @@ func NewDiskWidget() *DiskWidget {
updateInterval: time.Second,
Partitions: make(map[string]*Partition),
}
- self.Title = " Disk Usage "
- self.Header = []string{"Disk", "Mount", "Used", "Free", "R/s", "W/s"}
+ self.Table.Tr = tr
+ self.Title = tr.Value("widget.label.disk")
+ self.Header = []string{tr.Value("widget.disk.disk"), tr.Value("widget.disk.mount"), tr.Value("widget.disk.used"), tr.Value("widget.disk.free"), tr.Value("widget.disk.rs"), tr.Value("widget.disk.ws")}
self.ColGap = 2
self.ColResizer = func() {
self.ColWidths = []int{
@@ -73,7 +74,7 @@ func (disk *DiskWidget) EnableMetric() {
func (disk *DiskWidget) update() {
partitions, err := psDisk.Partitions(false)
if err != nil {
- log.Printf("failed to get disk partitions from gopsutil: %v", err)
+ log.Printf(tr.Value("error.setup", "disk-partitions", err.Error()))
return
}
@@ -118,7 +119,7 @@ func (disk *DiskWidget) update() {
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)
+ log.Printf(tr.Value("error.recovfetch", "partition-"+partition.MountPoint+"-usage", err.Error()))
continue
}
partition.UsedPercent = uint32(usage.UsedPercent + 0.5)
@@ -127,7 +128,7 @@ func (disk *DiskWidget) update() {
ioCounters, err := psDisk.IOCounters(partition.Device)
if err != nil {
- log.Printf("failed to get partition read/write info from gopsutil: %v. partition: %v", err, partition)
+ log.Printf(tr.Value("error.recovfetch", "partition-"+partition.Device+"-rw", err.Error()))
continue
}
ioCounter := ioCounters[strings.Replace(partition.Device, "/dev/", "", -1)]
diff --git a/widgets/help.go b/widgets/help.go
index a2c38e4..d98fecd 100644
--- a/widgets/help.go
+++ b/widgets/help.go
@@ -5,52 +5,19 @@ import (
"strings"
ui "github.com/gizak/termui/v3"
+ lingo "github.com/jdkeke142/lingo-toml"
)
-// KEYBINDS is the help text for the in-program shortcuts
-const KEYBINDS = `
-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 (15)
- - d3: kill selected process or group of processes with SIGQUIT (3)
- - d9: kill selected process or group of processes with SIGKILL (9)
-
-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
-
-Network:
- - b: toggle between mbps and scaled bytes per second
-`
+var tr lingo.Translations
+var keyBinds string
type HelpMenu struct {
ui.Block
}
-func NewHelpMenu() *HelpMenu {
+func NewHelpMenu(tra lingo.Translations) *HelpMenu {
+ tr = tra
+ keyBinds = tr.Value("help.help")
return &HelpMenu{
Block: *ui.NewBlock(),
}
@@ -58,12 +25,12 @@ func NewHelpMenu() *HelpMenu {
func (help *HelpMenu) Resize(termWidth, termHeight int) {
textWidth := 53
- for _, line := range strings.Split(KEYBINDS, "\n") {
+ for _, line := range strings.Split(keyBinds, "\n") {
if textWidth < len(line) {
textWidth = len(line) + 2
}
}
- textHeight := strings.Count(KEYBINDS, "\n") + 1
+ textHeight := strings.Count(keyBinds, "\n") + 1
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
@@ -73,7 +40,7 @@ func (help *HelpMenu) Resize(termWidth, termHeight int) {
func (help *HelpMenu) Draw(buf *ui.Buffer) {
help.Block.Draw(buf)
- for y, line := range strings.Split(KEYBINDS, "\n") {
+ for y, line := range strings.Split(keyBinds, "\n") {
for x, rune := range line {
buf.SetCell(
ui.NewCell(rune, ui.Theme.Default),
diff --git a/widgets/mem.go b/widgets/mem.go
index b994276..19656bb 100644
--- a/widgets/mem.go
+++ b/widgets/mem.go
@@ -21,7 +21,7 @@ func NewMemWidget(updateInterval time.Duration, horizontalScale int) *MemWidget
LineGraph: ui.NewLineGraph(),
updateInterval: updateInterval,
}
- widg.Title = " Memory Usage "
+ widg.Title = tr.Value("widget.label.mem")
widg.HorizontalScale = horizontalScale
mems := make(map[string]devices.MemoryInfo)
devices.UpdateMem(mems)
diff --git a/widgets/net.go b/widgets/net.go
index b76d6b4..f25f106 100644
--- a/widgets/net.go
+++ b/widgets/net.go
@@ -47,9 +47,9 @@ func NewNetWidget(netInterface string) *NetWidget {
updateInterval: time.Second,
NetInterface: strings.Split(netInterface, ","),
}
- self.Title = " Network Usage "
+ self.Title = tr.Value("widget.label.net")
if netInterface != "all" {
- self.Title = fmt.Sprintf(" Network Usage: %s ", netInterface)
+ self.Title = tr.Value("widget.label.netint", netInterface)
}
self.update()
@@ -73,7 +73,7 @@ func (net *NetWidget) EnableMetric() {
func (net *NetWidget) update() {
interfaces, err := psNet.IOCounters(true)
if err != nil {
- log.Printf("failed to get network activity from gopsutil: %v", err)
+ log.Println(tr.Value("widget.net.err.netactivity", err.Error()))
return
}
@@ -114,12 +114,14 @@ func (net *NetWidget) update() {
recentBytesSent = totalBytesSent - net.totalBytesSent
if int(recentBytesRecv) < 0 {
- log.Printf("error: negative value for recently received network data from gopsutil. recentBytesRecv: %v", recentBytesRecv)
+ v := fmt.Sprintf("%d", recentBytesRecv)
+ log.Println(tr.Value("widget.net.err.negvalrecv", v))
// recover from error
recentBytesRecv = 0
}
if int(recentBytesSent) < 0 {
- log.Printf("error: negative value for recently sent network data from gopsutil. recentBytesSent: %v", recentBytesSent)
+ v := fmt.Sprintf("%d", recentBytesSent)
+ log.Printf(tr.Value("widget.net.err.negvalsent", v))
// recover from error
recentBytesSent = 0
}
@@ -160,7 +162,7 @@ func (net *NetWidget) update() {
recentConverted, unitRecent = utils.ConvertBytes(recent)
}
- net.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConverted, unitTotal)
+ net.Lines[i].Title1 = fmt.Sprintf(" %s %s: %5.1f %s", tr.Value("total"), label, totalConverted, unitTotal)
net.Lines[i].Title2 = fmt.Sprintf(format, rate, recentConverted, unitRecent)
}
}
diff --git a/widgets/proc.go b/widgets/proc.go
index 218ba63..408906c 100644
--- a/widgets/proc.go
+++ b/widgets/proc.go
@@ -50,7 +50,7 @@ type ProcWidget struct {
func NewProcWidget() *ProcWidget {
cpuCount, err := devices.CpuCount()
if err != nil {
- log.Printf("failed to get CPU count from gopsutil: %v", err)
+ log.Println(tr.Value("error.proc.err.count", err.Error()))
}
self := &ProcWidget{
Table: ui.NewTable(),
@@ -62,14 +62,14 @@ func NewProcWidget() *ProcWidget {
}
self.entry = &ui.Entry{
Style: self.TitleStyle,
- Label: " Filter: ",
+ Label: tr.Value("widget.proc.filter"),
Value: "",
UpdateCallback: func(val string) {
self.filter = val
self.update()
},
}
- self.Title = " Processes "
+ self.Title = tr.Value("widget.proc.label")
self.ShowCursor = true
self.ShowLocation = true
self.ColGap = 3
@@ -136,7 +136,7 @@ func (proc *ProcWidget) filterProcs(procs []Proc) []Proc {
func (proc *ProcWidget) update() {
procs, err := getProcs()
if err != nil {
- log.Printf("failed to retrieve processes: %v", err)
+ log.Printf(tr.Value("widget.proc.error.retrieve", err.Error()))
return
}
@@ -156,10 +156,15 @@ func (proc *ProcWidget) update() {
// sortProcs sorts either the grouped or ungrouped []Process based on the sortMethod.
// Called with every update, when the sort method is changed, and when processes are grouped and ungrouped.
func (proc *ProcWidget) sortProcs() {
- proc.Header = []string{"Count", "Command", "CPU%", "Mem%"}
+ proc.Header = []string{
+ tr.Value("widget.proc.header.count"),
+ tr.Value("widget.proc.header.command"),
+ tr.Value("widget.proc.header.cpu"),
+ tr.Value("widget.proc.header.mem"),
+ }
if !proc.showGroupedProcs {
- proc.Header[0] = "PID"
+ proc.Header[0] = tr.Value("widget.proc.header.pid")
}
var procs *[]Proc
diff --git a/widgets/proc_freebsd.go b/widgets/proc_freebsd.go
index 34fee18..1df0c66 100644
--- a/widgets/proc_freebsd.go
+++ b/widgets/proc_freebsd.go
@@ -26,13 +26,13 @@ type processList struct {
func getProcs() ([]Proc, error) {
output, err := exec.Command("ps", "-axo pid,comm,%cpu,%mem,args", "--libxo", "json").Output()
if err != nil {
- return nil, fmt.Errorf("failed to execute 'ps' command: %v", err)
+ return nil, fmt.Errorf(tr.Value("widget.proc.err.ps", err.Error()))
}
list := processList{}
err = json.Unmarshal(output, &list)
if err != nil {
- return nil, fmt.Errorf("failed to unmarshal json. %s", err)
+ return nil, fmt.Errorf(tr.Value("widget.proc.err.parse", err.Error()))
}
procs := []Proc{}
@@ -42,15 +42,18 @@ func getProcs() ([]Proc, error) {
}
pid, err := strconv.Atoi(strings.TrimSpace(process.Pid))
if err != nil {
- log.Printf("failed to convert first field to int: %v. split: %v", err, process)
+ sp := fmt.Sprintf("%v", process)
+ log.Printf(tr.Value("widget.proc.err.pidconv", err.Error(), sp))
}
cpu, err := strconv.ParseFloat(utils.ConvertLocalizedString(process.CPU), 32)
if err != nil {
- log.Printf("failed to convert third field to float: %v. split: %v", err, process)
+ sp := fmt.Sprintf("%v", process)
+ log.Printf(tr.Value("widget.proc.err.cpuconv", err.Error(), sp))
}
mem, err := strconv.ParseFloat(utils.ConvertLocalizedString(process.Mem), 32)
if err != nil {
- log.Printf("failed to convert fourth field to float: %v. split: %v", err, process)
+ sp := fmt.Sprintf("%v", process)
+ log.Printf(tr.Value("widget.proc.err.memconv", err.Error(), sp))
}
proc := Proc{
Pid: pid,
diff --git a/widgets/proc_linux.go b/widgets/proc_linux.go
index 8fb53a0..b967c7b 100644
--- a/widgets/proc_linux.go
+++ b/widgets/proc_linux.go
@@ -11,7 +11,7 @@ import (
func getProcs() ([]Proc, error) {
output, err := exec.Command("ps", "-axo", "pid:10,comm:50,pcpu:5,pmem:5,args").Output()
if err != nil {
- return nil, fmt.Errorf("failed to execute 'ps' command: %v", err)
+ return nil, fmt.Errorf(tr.Value("widget.proc.err.ps", err.Error()))
}
// converts to []string, removing trailing newline and header
@@ -22,15 +22,15 @@ func getProcs() ([]Proc, error) {
log.Printf("line is '%s', pid is '%s', cpu is '%s', mem is '%s'", line, strings.TrimSpace(line[0:10]), strings.TrimSpace(line[63:68]), strings.TrimSpace(line[69:74]))
pid, err := strconv.Atoi(strings.TrimSpace(line[0:10]))
if err != nil {
- log.Printf("failed to convert PID to int: %v. line: %v", err, line)
+ log.Println(tr.Value("widget.proc.err.pidconv", err.Error(), line))
}
cpu, err := strconv.ParseFloat(strings.TrimSpace(line[63:68]), 64)
if err != nil {
- log.Printf("failed to convert CPU usage to float: %v. line: %v", err, line)
+ log.Println(tr.Value("widget.proc.err.cpuconv", err.Error(), line))
}
mem, err := strconv.ParseFloat(strings.TrimSpace(line[69:74]), 64)
if err != nil {
- log.Printf("failed to convert Mem usage to float: %v. line: %v", err, line)
+ log.Println(tr.Value("widget.proc.err.memconv", err.Error(), line))
}
proc := Proc{
Pid: pid,
diff --git a/widgets/proc_other.go b/widgets/proc_other.go
index b761431..a485c4f 100644
--- a/widgets/proc_other.go
+++ b/widgets/proc_other.go
@@ -23,7 +23,7 @@ func getProcs() ([]Proc, error) {
keywords := fmt.Sprintf("pid=%s,comm=%s,pcpu=%s,pmem=%s,args", ten, fifty, five, five)
output, err := exec.Command("ps", "-caxo", keywords).Output()
if err != nil {
- return nil, fmt.Errorf("failed to execute 'ps' command: %v", err)
+ return nil, fmt.Errorf(tr.Value("widget.proc.err.ps", err.Error()))
}
// converts to []string and removes the header
@@ -33,15 +33,15 @@ func getProcs() ([]Proc, error) {
for _, line := range linesOfProcStrings {
pid, err := strconv.Atoi(strings.TrimSpace(line[0:10]))
if err != nil {
- log.Printf("failed to convert first field to int: %v. split: %v", err, line)
+ log.Println(tr.Value("widget.proc.err.pidconv", err.Error(), line))
}
cpu, err := strconv.ParseFloat(utils.ConvertLocalizedString(strings.TrimSpace(line[63:68])), 64)
if err != nil {
- log.Printf("failed to convert third field to float: %v. split: %v", err, line)
+ log.Println(tr.Value("widget.proc.err.cpuconv", err.Error(), line))
}
mem, err := strconv.ParseFloat(utils.ConvertLocalizedString(strings.TrimSpace(line[69:74])), 64)
if err != nil {
- log.Printf("failed to convert fourth field to float: %v. split: %v", err, line)
+ log.Println(tr.Value("widget.proc.err.memconv", err.Error(), line))
}
proc := Proc{
Pid: pid,
diff --git a/widgets/proc_windows.go b/widgets/proc_windows.go
index 56590c7..1d8bffc 100644
--- a/widgets/proc_windows.go
+++ b/widgets/proc_windows.go
@@ -3,14 +3,15 @@ package widgets
import (
"fmt"
"log"
+ "strconv"
- psProc "github.com/shirou/gopsutil/process"
+ "github.com/shirou/gopsutil/process"
)
func getProcs() ([]Proc, error) {
- psProcs, err := psProc.Processes()
+ psProcs, err := process.Processes()
if err != nil {
- return nil, fmt.Errorf("failed to get processes from gopsutil: %v", err)
+ return nil, fmt.Errorf(tr.Value("widget.proc.err.gopsutil", err.Error()))
}
procs := make([]Proc, len(psProcs))
@@ -18,15 +19,24 @@ func getProcs() ([]Proc, error) {
pid := psProc.Pid
command, err := psProc.Name()
if err != nil {
- log.Printf("failed to get process command from gopsutil: %v. psProc: %v. i: %v. pid: %v", err, psProc, i, pid)
+ sps := fmt.Sprintf("%v", psProc)
+ si := strconv.Itoa(i)
+ spid := fmt.Sprintf("%d", pid)
+ log.Println(tr.Value("widget.proc.err.getcmd", err.Error(), sps, si, spid))
}
cpu, err := psProc.CPUPercent()
if err != nil {
- log.Printf("failed to get process cpu usage from gopsutil: %v. psProc: %v. i: %v. pid: %v", err, psProc, i, pid)
+ sps := fmt.Sprintf("%v", psProc)
+ si := strconv.Itoa(i)
+ spid := fmt.Sprintf("%d", pid)
+ log.Println(tr.Value("widget.proc.err.cpupercent", err.Error(), sps, si, spid))
}
mem, err := psProc.MemoryPercent()
if err != nil {
- log.Printf("failed to get process memeory usage from gopsutil: %v. psProc: %v. i: %v. pid: %v", err, psProc, i, pid)
+ sps := fmt.Sprintf("%v", psProc)
+ si := strconv.Itoa(i)
+ spid := fmt.Sprintf("%d", pid)
+ log.Println(tr.Value("widget.proc.err.mempercent", err.Error(), sps, si, spid))
}
procs[i] = Proc{
diff --git a/widgets/statusbar.go b/widgets/statusbar.go
index 2242414..4727960 100644
--- a/widgets/statusbar.go
+++ b/widgets/statusbar.go
@@ -24,7 +24,7 @@ func (sb *StatusBar) Draw(buf *ui.Buffer) {
hostname, err := os.Hostname()
if err != nil {
- log.Printf("could not get hostname: %v", err)
+ log.Printf(tr.Value("error.nohostname", err.Error()))
return
}
buf.SetString(
diff --git a/widgets/temp.go b/widgets/temp.go
index 5a22897..f5632df 100644
--- a/widgets/temp.go
+++ b/widgets/temp.go
@@ -39,7 +39,7 @@ func NewTempWidget(tempScale TempScale, filter []string) *TempWidget {
TempThreshold: 80,
TempScale: tempScale,
}
- self.Title = " Temperatures "
+ self.Title = tr.Value("widget.label.temp")
if len(filter) > 0 {
for _, t := range filter {
self.Data[t] = 0