Fix process localization issues on FreeBSD

This commit is contained in:
Matthias Gamsjager 2019-05-28 11:42:40 -07:00 committed by Caleb Bassi
parent 235c386a6c
commit 6907f598f8
2 changed files with 17 additions and 4 deletions

13
src/utils/conversions.go Normal file
View File

@ -0,0 +1,13 @@
package utils
import (
"strings"
)
func ConvertLocalizedString(s string) string {
if strings.ContainsAny(s, ",") {
return strings.Replace(s, ",", ".", 1)
} else {
return s
}
}

View File

@ -1,5 +1,3 @@
// +build freebsd
package widgets
import (
@ -9,6 +7,8 @@ import (
"os/exec"
"strconv"
"strings"
"github.com/cjbassi/gotop/src/utils"
)
type processList struct {
@ -44,11 +44,11 @@ func getProcs() ([]Proc, error) {
if err != nil {
log.Printf("failed to convert first field to int: %v. split: %v", err, process)
}
cpu, err := strconv.ParseFloat(process.Cpu, 64)
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)
}
mem, err := strconv.ParseFloat(process.Mem, 64)
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)
}