From 444d2624ab6d5b054446a08ad6888126f9d3494c Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Tue, 5 May 2020 08:13:25 -0500 Subject: More translation work. Incomplete. --- widgets/battery.go | 12 ++++++------ widgets/batterygauge.go | 6 +++--- widgets/cpu.go | 4 ++-- widgets/disk.go | 12 ++++++------ widgets/help.go | 51 +++++++++---------------------------------------- 5 files changed, 26 insertions(+), 59 deletions(-) (limited to 'widgets') diff --git a/widgets/battery.go b/widgets/battery.go index 7167668..dc21d60 100644 --- a/widgets/battery.go +++ b/widgets/battery.go @@ -24,7 +24,7 @@ func NewBatteryWidget(horizontalScale int) *BatteryWidget { LineGraph: ui.NewLineGraph(), updateInterval: time.Minute, } - self.Title = " Battery Status " + self.Title = tr.Value("widget.battery") self.HorizontalScale = horizontalScale // intentional duplicate @@ -46,7 +46,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 } b.metric = make([]prometheus.Gauge, len(bats)) @@ -63,7 +63,7 @@ func (b *BatteryWidget) EnableMetric() { } func makeID(i int) string { - return "Batt" + strconv.Itoa(i) + return tr.Value("widget.batt") + strconv.Itoa(i) } func (b *BatteryWidget) Scale(i int) { @@ -75,7 +75,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) @@ -83,11 +83,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 968a63c..bb44e57 100644 --- a/widgets/batterygauge.go +++ b/widgets/batterygauge.go @@ -19,7 +19,7 @@ type BatteryGauge struct { func NewBatteryGauge() *BatteryGauge { self := &BatteryGauge{Gauge: termui.NewGauge()} - self.Title = " Power Level " + self.Title = tr.Value("widget.gauge") self.update() @@ -37,7 +37,7 @@ func NewBatteryGauge() *BatteryGauge { func (b *BatteryGauge) EnableMetric() { bats, err := battery.GetAll() if err != nil { - log.Printf("error setting up metrics: %v", err) + log.Printf(tr.Value("error.metricsetup", "power", err.Error())) return } mx := 0.0 @@ -60,7 +60,7 @@ func (b *BatteryGauge) update() { // FIXME: Getting a lot of these in the logs bats, err := battery.GetAll() if err != nil { - log.Printf("error setting up batteries: %v", err) + log.Printf(tr.Value("error.setup", "power", err.Error())) return } mx := 0.0 diff --git a/widgets/cpu.go b/widgets/cpu.go index 03346bf..8aaad7e 100644 --- a/widgets/cpu.go +++ b/widgets/cpu.go @@ -32,7 +32,7 @@ func NewCPUWidget(updateInterval time.Duration, horizontalScale int, showAverage ShowAverageLoad: showAverageLoad, ShowPerCPULoad: showPerCPULoad, } - self.Title = " CPU Usage " + self.Title = tr.Value("cpu") self.HorizontalScale = horizontalScale if !(self.ShowAverageLoad || self.ShowPerCPULoad) { @@ -129,7 +129,7 @@ func (cpu *CPUWidget) update() { cpu.Labels[key] = fmt.Sprintf("%d%%", percent) if cpu.metric != nil { if cpu.metric[key] == nil { - log.Printf("no metrics for %s", key) + log.Printf(tr.Value("error.nometrics", "cpu", key)) } else { cpu.metric[key].Set(float64(percent)) } diff --git a/widgets/disk.go b/widgets/disk.go index 0c86dc9..dd79832 100644 --- a/widgets/disk.go +++ b/widgets/disk.go @@ -38,8 +38,8 @@ 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.Title = tr.Value("widget.disk") + self.Header = []string{tr.Value("disk.disk"), tr.Value("disk.mount"), tr.Value("disk.used"), tr.Value("disk.free"), tr.Value("disk.rs"), tr.Value("disk.ws")} self.ColGap = 2 self.ColResizer = func() { self.ColWidths = []int{ @@ -80,7 +80,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 } @@ -125,7 +125,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) @@ -134,7 +134,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)] @@ -176,7 +176,7 @@ func (disk *DiskWidget) update() { disk.Rows[i][5] = partition.BytesWrittenRecently if disk.metric != nil { if disk.metric[key] == nil { - log.Printf("ERROR: missing metric %s", key) + log.Printf(tr.Value("error.nometrics", "disk", key)) } else { disk.metric[key].Set(float64(partition.UsedPercent) / 100.0) } diff --git a/widgets/help.go b/widgets/help.go index a2c38e4..fff71a7 100644 --- a/widgets/help.go +++ b/widgets/help.go @@ -5,52 +5,19 @@ import ( "strings" ui "github.com/gizak/termui/v3" + "github.com/xxxserxxx/lingo" ) -// KEYBINDS is the help text for the in-program shortcuts -const KEYBINDS = ` -Quit: q or - -Process navigation: - - k and : up - - j and : down - - : half page up - - : half page down - - : full page up - - : full page down - - gg and : jump to top - - G and : jump to bottom - -Process actions: - - : 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): - - : accept filter - - and : 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("widgets.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), -- cgit v1.2.3 From b6b75415247f23fda5c91db2d8065e045c97b625 Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Thu, 18 Jun 2020 19:51:01 -0500 Subject: Expand translations --- widgets/battery.go | 4 ++-- widgets/batterygauge.go | 2 +- widgets/cpu.go | 2 +- widgets/disk.go | 2 +- widgets/mem.go | 2 +- widgets/net.go | 14 ++++++++------ widgets/proc.go | 17 +++++++++++------ widgets/proc_linux.go | 8 ++++---- widgets/proc_other.go | 8 ++++---- widgets/proc_windows.go | 8 ++++---- widgets/temp.go | 2 +- 11 files changed, 38 insertions(+), 31 deletions(-) (limited to 'widgets') diff --git a/widgets/battery.go b/widgets/battery.go index 7bc9ca6..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 = tr.Value("widget.battery") + self.Title = tr.Value("widget.label.battery") self.HorizontalScale = horizontalScale // intentional duplicate @@ -60,7 +60,7 @@ func (b *BatteryWidget) EnableMetric() { } func makeID(i int) string { - return tr.Value("widget.batt") + strconv.Itoa(i) + return tr.Value("widget.label.batt") + strconv.Itoa(i) } func (b *BatteryWidget) Scale(i int) { diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go index bec3c43..8dd681e 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 = tr.Value("widget.gauge") + self.Title = tr.Value("widget.label.gauge") self.update() diff --git a/widgets/cpu.go b/widgets/cpu.go index 207b231..4d2bc89 100644 --- a/widgets/cpu.go +++ b/widgets/cpu.go @@ -32,7 +32,7 @@ func NewCPUWidget(updateInterval time.Duration, horizontalScale int, showAverage ShowPerCPULoad: showPerCPULoad, cpuLoads: make(map[string]float64), } - self.Title = tr.Value("cpu") + 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 716e631..67f3bb6 100644 --- a/widgets/disk.go +++ b/widgets/disk.go @@ -37,7 +37,7 @@ func NewDiskWidget() *DiskWidget { updateInterval: time.Second, Partitions: make(map[string]*Partition), } - self.Title = tr.Value("widget.disk") + self.Title = tr.Value("widget.label.disk") self.Header = []string{tr.Value("disk.disk"), tr.Value("disk.mount"), tr.Value("disk.used"), tr.Value("disk.free"), tr.Value("disk.rs"), tr.Value("disk.ws")} self.ColGap = 2 self.ColResizer = func() { 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 f47f646..ee94825 100644 --- a/widgets/proc.go +++ b/widgets/proc.go @@ -51,7 +51,7 @@ type ProcWidget struct { func NewProcWidget() *ProcWidget { cpuCount, err := psCPU.Counts(false) 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(), @@ -63,14 +63,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 @@ -137,7 +137,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 } @@ -157,10 +157,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_linux.go b/widgets/proc_linux.go index 164319d..938e5c2 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 @@ -21,15 +21,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 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..d34ef5e 100644 --- a/widgets/proc_windows.go +++ b/widgets/proc_windows.go @@ -10,7 +10,7 @@ import ( func getProcs() ([]Proc, error) { psProcs, err := psProc.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 +18,15 @@ 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) + log.Println(tr.Value("widget.proc.err.getcmd", err, psProc, i, pid)) } 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) + log.Println(tr.Value("widget.proc.err.cpupercent", err, psProc, i, pid)) } 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) + log.Println(tr.Value("widget.proc.err.mempercent", err, psProc, i, pid)) } procs[i] = Proc{ 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 -- cgit v1.2.3 From 9a56571373eb5a9ea9261afb39bebaf7ddeb700f Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Sat, 20 Jun 2020 08:33:01 -0500 Subject: Fixes the help text issue. Moved some hard-coded strings to the translation files. --- widgets/help.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'widgets') diff --git a/widgets/help.go b/widgets/help.go index fff71a7..d98fecd 100644 --- a/widgets/help.go +++ b/widgets/help.go @@ -5,7 +5,7 @@ import ( "strings" ui "github.com/gizak/termui/v3" - "github.com/xxxserxxx/lingo" + lingo "github.com/jdkeke142/lingo-toml" ) var tr lingo.Translations @@ -17,7 +17,7 @@ type HelpMenu struct { func NewHelpMenu(tra lingo.Translations) *HelpMenu { tr = tra - keyBinds = tr.Value("widgets.help") + keyBinds = tr.Value("help.help") return &HelpMenu{ Block: *ui.NewBlock(), } -- cgit v1.2.3 From 23364aa754c836b8a5fbc69adbdbd49abd183a57 Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Sat, 20 Jun 2020 16:47:48 -0500 Subject: More strings moved to translations --- widgets/disk.go | 1 + widgets/proc_freebsd.go | 10 +++++----- widgets/statusbar.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'widgets') diff --git a/widgets/disk.go b/widgets/disk.go index 67f3bb6..726e629 100644 --- a/widgets/disk.go +++ b/widgets/disk.go @@ -37,6 +37,7 @@ func NewDiskWidget() *DiskWidget { updateInterval: time.Second, Partitions: make(map[string]*Partition), } + self.Table.Tr = tr self.Title = tr.Value("widget.label.disk") self.Header = []string{tr.Value("disk.disk"), tr.Value("disk.mount"), tr.Value("disk.used"), tr.Value("disk.free"), tr.Value("disk.rs"), tr.Value("disk.ws")} self.ColGap = 2 diff --git a/widgets/proc_freebsd.go b/widgets/proc_freebsd.go index 34fee18..a938636 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,15 @@ 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) + log.Printf(tr.Value("widget.proc.err.pidconv", err.Error(), process)) } 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) + log.Printf(tr.Value("widget.proc.err.cpuconv", err.Error(), process)) } 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) + log.Printf(tr.Value("widget.proc.err.memconv", err.Error(), process)) } proc := Proc{ Pid: pid, 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( -- cgit v1.2.3 From 81424fb000eaf1b6cd8c1d5bb4d476cb4b3b32db Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Sun, 21 Jun 2020 11:49:04 -0500 Subject: Fix windows compile errors. --- widgets/proc_windows.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'widgets') diff --git a/widgets/proc_windows.go b/widgets/proc_windows.go index d34ef5e..1d8bffc 100644 --- a/widgets/proc_windows.go +++ b/widgets/proc_windows.go @@ -3,12 +3,13 @@ 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(tr.Value("widget.proc.err.gopsutil", err.Error())) } @@ -18,15 +19,24 @@ func getProcs() ([]Proc, error) { pid := psProc.Pid command, err := psProc.Name() if err != nil { - log.Println(tr.Value("widget.proc.err.getcmd", 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.Println(tr.Value("widget.proc.err.cpupercent", 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.Println(tr.Value("widget.proc.err.mempercent", 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{ -- cgit v1.2.3 From ccf7a6822f217c84f4feb9d860cb6c9ffeb7688b Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Mon, 22 Jun 2020 10:23:10 -0500 Subject: Fix build errors on FreeBSD --- widgets/proc_freebsd.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'widgets') diff --git a/widgets/proc_freebsd.go b/widgets/proc_freebsd.go index a938636..1df0c66 100644 --- a/widgets/proc_freebsd.go +++ b/widgets/proc_freebsd.go @@ -42,15 +42,18 @@ func getProcs() ([]Proc, error) { } pid, err := strconv.Atoi(strings.TrimSpace(process.Pid)) if err != nil { - log.Printf(tr.Value("widget.proc.err.pidconv", err.Error(), 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(tr.Value("widget.proc.err.cpuconv", err.Error(), 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(tr.Value("widget.proc.err.memconv", err.Error(), process)) + sp := fmt.Sprintf("%v", process) + log.Printf(tr.Value("widget.proc.err.memconv", err.Error(), sp)) } proc := Proc{ Pid: pid, -- cgit v1.2.3 From edf0c2a3a8edd43a685ef91c2e3f9f3ea7d5bc23 Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Tue, 25 Aug 2020 08:23:42 -0500 Subject: Fixes bad label keys in disk widget; finishes Esperanto translation. --- widgets/disk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widgets') diff --git a/widgets/disk.go b/widgets/disk.go index 726e629..9df3c3b 100644 --- a/widgets/disk.go +++ b/widgets/disk.go @@ -39,7 +39,7 @@ func NewDiskWidget() *DiskWidget { } self.Table.Tr = tr self.Title = tr.Value("widget.label.disk") - self.Header = []string{tr.Value("disk.disk"), tr.Value("disk.mount"), tr.Value("disk.used"), tr.Value("disk.free"), tr.Value("disk.rs"), tr.Value("disk.ws")} + 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{ -- cgit v1.2.3