summaryrefslogtreecommitdiffstats
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
parent72cde0545887f98e58423c1495327276daa202b5 (diff)
parentedf0c2a3a8edd43a685ef91c2e3f9f3ea7d5bc23 (diff)
Resolves merge conflicts
-rw-r--r--LICENSE44
-rw-r--r--README.md5
-rw-r--r--cmd/gotop/main.go124
-rw-r--r--colorschemes/registry.go14
-rw-r--r--config.go32
-rw-r--r--devices/devices.go6
-rw-r--r--devices/smc.go28
-rw-r--r--devices/temp.go4
-rw-r--r--devices/temp_freebsd.go6
-rw-r--r--go.mod2
-rw-r--r--go.sum24
-rw-r--r--layout/layout.go6
-rw-r--r--layout/parser.go9
-rw-r--r--logging/logging.go5
-rw-r--r--termui/table.go7
-rw-r--r--translations/dicts.go404
-rw-r--r--translations/dicts/de_DE.toml180
-rw-r--r--translations/dicts/en_US.toml180
-rw-r--r--translations/dicts/eo.toml182
-rw-r--r--translations/dicts/tt_TT.toml180
-rw-r--r--translations/dicts/zh_CN.toml180
-rw-r--r--translations/en_US.toml44
-rw-r--r--translations/zh_CN.toml44
-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
37 files changed, 1558 insertions, 318 deletions
diff --git a/LICENSE b/LICENSE
index 0a126e1..abb389e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,29 +1,25 @@
-The MIT License (MIT)
+The MIT License (Festival variant)
-Copyright (c) 2020 Sean E. Russell <ser@ser1.net> 87651D71
+Permission is hereby granted, free of charge, to use and distribute this
+software and its documentation without restriction, including without
+limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of this work, and to permit persons to whom
+this work is furnished to do so, subject to the following conditions:
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
+1. The codemust retain the above copyright notice, this list of conditions
+ and the following disclaimer.
+2. Any modifications must be clearly marked as such.
+3. Original authors' names are not deleted.
+4. The authors' names are not used to endorse or promote products derived
+ from this software without specific prior written permission.
-1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
+THE COPYRIGHT HOLDERS AND THE CONTRIBUTORS TO THIS WORK DISCLAIM ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS NOR THE
+CONTRIBUTORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
+OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-3. Neither the name of the copyright holder nor the names of its
-contributors may be used to endorse or promote products derived from this
-software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+https://fedoraproject.org/wiki/Licensing:MIT?rd=Licensing/MIT#Festival_variant
diff --git a/README.md b/README.md
index 6956921..09e1d9c 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,10 @@ Move `gotop` to somewhere in your `$PATH`.
If Go is not installed or is the wrong version, and you don't have root access or don't want to upgrade Go, a script is provided to download Go and the gotop sources, compile gotop, and then clean up. See `scripts/install_without_root.sh`.
+#### go generate
+
+Apple SMC tags are embedded in a text file that is compiled into the executable; the same happens with the language translations. When the file `devices/data/sm.tsv` or any translations in `translations/dicts/` change, `go generate` should be re-run.
+
## Usage
Run with `-h` to get an extensive list of command line arguments. Many of these can be configured by creating a configuration file; see the next section for more information. Key bindings can be viewed while gotop is running by pressing the `?` key, or they can be printed out by using the `--list keys` command.
@@ -114,6 +118,7 @@ For more information on other topics, see:
- [goreleaser/nfpm](https://github.com/goreleaser/nfpm)
- [distatus/battery](https://github.com/distatus/battery)
- [VictoriaMetrics/metrics](https://github.com/VictoriaMetrics/metrics) Check this out! The API is clean, elegant, introduces many fewer indirect dependencies than the Prometheus client, and adds 50% less size to binaries.
+- [lingo-toml](https://github.com/jdkeke142/lingo-toml) provides the translation support library.
## History
diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go
index f9f6618..3545470 100644
--- a/cmd/gotop/main.go
+++ b/cmd/gotop/main.go
@@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io"
+ "io/ioutil"
"log"
"net/http"
"os"
@@ -18,7 +19,9 @@ import (
//_ "net/http/pprof"
"github.com/VictoriaMetrics/metrics"
+ jj "github.com/cloudfoundry-attic/jibber_jabber"
ui "github.com/gizak/termui/v3"
+ "github.com/jdkeke142/lingo-toml"
"github.com/shibukawa/configdir"
"github.com/xxxserxxx/opflag"
@@ -27,7 +30,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"
+ "github.com/xxxserxxx/gotop/v4/translations"
w "github.com/xxxserxxx/gotop/v4/widgets"
)
@@ -50,6 +53,7 @@ var (
bar *w.StatusBar
statusbar bool
stderrLogger = log.New(os.Stderr, "", 0)
+ tr lingo.Translations
)
func parseArgs() error {
@@ -58,33 +62,27 @@ func parseArgs() error {
for i, p := range cds {
cpaths[i] = p.Path
}
- help := opflag.BoolP("help", "h", false, "Show this screen.")
- color := opflag.StringP("color", "c", conf.Colorscheme.Name, "Set a colorscheme.")
- opflag.IntVarP(&conf.GraphHorizontalScale, "graphscale", "S", conf.GraphHorizontalScale, "Graph scale factor, >0")
- version := opflag.BoolP("version", "v", false, "Print version and exit.")
- versioN := opflag.BoolP("", "V", false, "Print version and exit.")
- opflag.BoolVarP(&conf.PercpuLoad, "percpu", "p", conf.PercpuLoad, "Show each CPU in the CPU widget.")
- opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, "Show average CPU in the CPU widget.")
- fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', "Show temperatures in fahrenheit.Show temperatures in fahrenheit.")
- opflag.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, "Show a statusbar with the time.")
- opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, "Refresh frequency. Most time units accepted. `1m` = refresh every minute. `100ms` = refresh every 100ms.")
- opflag.StringVarP(&conf.Layout, "layout", "l", conf.Layout, `Name of layout spec file for the UI. Use "-" to pipe.`)
- opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", "Select network interface. Several interfaces can be defined using comma separated values. Interfaces can also be ignored using `!`")
- opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, "Enable metrics for export on the specified port.")
- opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, "Show network rate as mbps.")
- opflag.BoolVar(&conf.Test, "test", conf.Test, "Runs tests and exits with success/failure code.")
- opflag.StringP("", "C", "", "Config file to use instead of default (MUST BE FIRST ARGUMENT)")
- list := opflag.String("list", "", `List <devices|layouts|colorschemes|paths|keys>
- devices: Prints out device names for filterable widgets
- layouts: Lists build-in layouts
- colorschemes: Lists built-in colorschemes
- paths: List out configuration file search paths
- widgets: Widgets that can be used in a layout
- keys: Show the keyboard bindings.`)
- wc := opflag.Bool("write-config", false, "Write out a default config file.")
+ help := opflag.BoolP("help", "h", false, tr.Value("args.help"))
+ color := opflag.StringP("color", "c", conf.Colorscheme.Name, tr.Value("args.color"))
+ opflag.IntVarP(&conf.GraphHorizontalScale, "graphscale", "S", conf.GraphHorizontalScale, tr.Value("args.scale"))
+ version := opflag.BoolP("version", "v", false, tr.Value("args.version"))
+ versioN := opflag.BoolP("", "V", false, tr.Value("args.version"))
+ opflag.BoolVarP(&conf.PercpuLoad, "percpu", "p", conf.PercpuLoad, tr.Value("args.percpu"))
+ opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, tr.Value("args.cpuavg"))
+ fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', tr.Value("args.temp"))
+ opflag.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, tr.Value("args.statusbar"))
+ opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, tr.Value("args.rate"))
+ opflag.StringVarP(&conf.Layout, "layout", "l", conf.Layout, tr.Value("args.layout"))
+ opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", tr.Value("args.net"))
+ opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, tr.Value("args.export"))
+ opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps"))
+ opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test"))
+ opflag.StringP("", "C", "", tr.Value("args.conffile"))
+ list := opflag.String("list", "", tr.Value("args.list"))
+ wc := opflag.Bool("write-config", false, tr.Value("args.write"))
opflag.SortFlags = false
opflag.Usage = func() {
- fmt.Fprintf(os.Stderr, "Usage: %s [options]\n\nOptions:\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, tr.Value("usage", os.Args[0]))
opflag.PrintDefaults()
}
opflag.Parse()
@@ -109,25 +107,26 @@ func parseArgs() error {
if *list != "" {
switch *list {
case "layouts":
- fmt.Println(_layouts)
+ fmt.Println(tr.Value("help.layouts"))
case "colorschemes":
- fmt.Println(_colorschemes)
+ fmt.Println(tr.Value("help.colorschemes"))
case "paths":
- fmt.Println("Loadable colorschemes & layouts, and the config file, are searched for, in order:")
+ fmt.Println(tr.Value("help.paths"))
paths := make([]string, 0)
for _, d := range conf.ConfigDir.QueryFolders(configdir.All) {
paths = append(paths, d.Path)
}
fmt.Println(strings.Join(paths, "\n"))
- fmt.Printf("\nThe log file is in %s\n", filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE))
+ fmt.Println()
+ fmt.Println(tr.Value("help.log", filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE)))
case "devices":
listDevices()
case "keys":
- fmt.Println(widgets.KEYBINDS)
+ fmt.Println(tr.Value("help.help"))
case "widgets":
- fmt.Println(_widgets)
+ fmt.Println(tr.Value("help.widgets"))
default:
- fmt.Printf("Unknown option \"%s\"; try layouts, colorschemes, keys, paths, or devices\n", *list)
+ fmt.Printf(tr.Value("error.unknownopt", *list))
os.Exit(1)
}
os.Exit(0)
@@ -135,10 +134,10 @@ func parseArgs() error {
if *wc {
path, err := conf.Write()
if err != nil {
- fmt.Printf("Failed to write configuration file: %s\n", err)
+ fmt.Println(tr.Value("error.writefail", err.Error()))
os.Exit(1)
}
- fmt.Printf("Config written to %s\n", path)
+ fmt.Println(tr.Value("help.written", path))
os.Exit(0)
}
return nil
@@ -345,38 +344,55 @@ func main() {
ec := run()
if ec > 0 {
if ec < 2 {
- fmt.Printf("errors encountered; check the log file %s\n", filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE))
+ logpath := filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE)
+ fmt.Println(tr.Value("error.checklog", logpath))
+ bs, _ := ioutil.ReadFile(logpath)
+ fmt.Println(string(bs))
}
}
os.Exit(ec)
}
func run() int {
+ ling, err := lingo.New("en_US", "translations", translations.AssetFile())
+ if err != nil {
+ fmt.Printf("failed to load language files: %s\n", err)
+ return 2
+ }
+ lang, err := jj.DetectIETF()
+ if err != nil {
+ lang = "en_US"
+ }
+ lang = strings.Replace(lang, "-", "_", -1)
+ // Get the locale from the os
+ tr = ling.TranslationsForLocale(lang)
+ colorschemes.SetTr(tr)
conf = gotop.NewConfig()
+ conf.Tr = tr
// Find the config file; look in (1) local, (2) user, (3) global
// Check the last argument first
fs := flag.NewFlagSet("config", flag.ContinueOnError)
- cfg := fs.String("C", "", "Config file")
+ cfg := fs.String("C", "", tr.Value("configfile"))
fs.SetOutput(bufio.NewWriter(nil))
fs.Parse(os.Args[1:])
if *cfg != "" {
conf.ConfigFile = *cfg
}
- err := conf.Load()
+ err = conf.Load()
if err != nil {
- fmt.Printf("failed to parse config file: %s\n", err)
+ fmt.Println(tr.Value("error.configparse", err.Error()))
return 2
}
// Override with command line arguments
err = parseArgs()
if err != nil {
- fmt.Printf("parsing CLI args: %s\n", err)
+ fmt.Println(tr.Value("error.cliparse", err.Error()))
return 2
}
logfile, err := logging.New(conf)
if err != nil {
- fmt.Printf("failed to setup log file: %v\n", err)
+ fmt.Println(tr.Value("logsetup", err.Error()))
return 2
}
defer logfile.Close()
@@ -407,7 +423,7 @@ func run() int {
defer ui.Close()
setDefaultTermuiColors(conf) // done before initializing widgets to allow inheriting colors
- help = w.NewHelpMenu()
+ help = w.NewHelpMenu(tr)
if statusbar {
bar = w.NewStatusBar()
}
@@ -467,7 +483,7 @@ func getLayout(conf gotop.Config) (io.Reader, error) {
for _, d := range conf.ConfigDir.QueryFolders(configdir.Existing) {
paths = append(paths, d.Path)
}
- return nil, fmt.Errorf("unable find layout file %s in %s", conf.Layout, strings.Join(paths, ", "))
+ return nil, fmt.Errorf(tr.Value("error.findlayout", conf.Layout, strings.Join(paths, ", ")))
}
lo, err := folder.ReadFile(conf.Layout)
if err != nil {
@@ -492,25 +508,3 @@ func listDevices() {
}
}
}
-
-const _layouts = `Built-in layouts:
- default
- minimal
- battery
- kitchensink`
-const _colorschemes = `Built-in colorschemes:
- default
- default-dark (for white background)
- solarized
- solarized16-dark
- solarized16-light
- monokai
- vice`
-const _widgets = `Widgets that can be used in layouts:
- cpu - CPU load graph
- mem - Physical & swap memory use graph
- temp - Sensor temperatures
- disk - Physical disk partition use
- power - A battery bar
- net - Network load
- procs - Interactive process list`
diff --git a/colorschemes/registry.go b/colorschemes/registry.go
index baa4bda..84b2e89 100644
--- a/colorschemes/registry.go
+++ b/colorschemes/registry.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"
+ "github.com/jdkeke142/lingo-toml"
"github.com/shibukawa/configdir"
)
@@ -17,6 +18,13 @@ func init() {
}
}
+var tr lingo.Translations
+
+// Set the translation library
+func SetTr(tra lingo.Translations) {
+ tr = tra
+}
+
// FromName loads a Colorscheme by name; confDir is used to search
// directories for a scheme matching the name. The search order
// is the same as for config files.
@@ -46,15 +54,15 @@ func getCustomColorscheme(confDir configdir.ConfigDir, name string) (Colorscheme
for _, d := range confDir.QueryFolders(configdir.Existing) {
paths = append(paths, d.Path)
}
- return cs, fmt.Errorf("failed to find colorscheme file %s in %s", fn, strings.Join(paths, ", "))
+ return cs, fmt.Errorf(tr.Value("error.colorschemefile", fn, strings.Join(paths, ", ")))
}
dat, err := folder.ReadFile(fn)
if err != nil {
- return cs, fmt.Errorf("failed to read colorscheme file %s: %v", filepath.Join(folder.Path, fn), err)
+ return cs, fmt.Errorf(tr.Value("error.colorschemeload", filepath.Join(folder.Path, fn), err.Error()))
}
err = json.Unmarshal(dat, &cs)
if err != nil {
- return cs, fmt.Errorf("failed to parse colorscheme file: %v", err)
+ return cs, fmt.Errorf(tr.Value("error.colorschemeparse", err.Error()))
}
return cs, nil
}
diff --git a/config.go b/config.go
index 5da6f32..e37f184 100644
--- a/config.go
+++ b/config.go
@@ -1,5 +1,8 @@
package gotop
+//go:generate go-bindata -fs -pkg translations -prefix translations -o translations/dicts.go translations/dicts
+//go:generate go-bindata -pkg devices -prefix devices/data -o devices/smc.go devices/data
+
import (
"bufio"
"bytes"
@@ -13,6 +16,7 @@ import (
"strings"
"time"
+ "github.com/jdkeke142/lingo-toml"
"github.com/shibukawa/configdir"
"github.com/xxxserxxx/gotop/v4/colorschemes"
"github.com/xxxserxxx/gotop/v4/widgets"
@@ -40,6 +44,7 @@ type Config struct {
Test bool
ExtensionVars map[string]string
ConfigFile string
+ Tr lingo.Translations
}
func NewConfig() Config {
@@ -97,18 +102,15 @@ func load(in io.Reader, conf *Config) error {
}
kv := strings.Split(l, "=")
if len(kv) != 2 {
- return fmt.Errorf("bad config file syntax; should be KEY=VALUE, was %s", l)
+ return fmt.Errorf(conf.Tr.Value("config.err.configsyntax", l))
}
key := strings.ToLower(kv[0])
+ ln := strconv.Itoa(lineNo)
switch key {
default:
conf.ExtensionVars[key] = kv[1]
- case "configdir":
- log.Printf("configdir is deprecated. Ignored configdir=%s", kv[1])
- case "logdir":
- log.Printf("logdir is deprecated. Ignored logdir=%s", kv[1])
- case "logfile":
- log.Printf("logfile is deprecated. Ignored logfile=%s", kv[1])
+ case "configdir", "logdir", "logfile":
+ log.Printf(conf.Tr.Value("config.err.deprecation", ln, key, kv[1]))
case graphhorizontalscale:
iv, err := strconv.Atoi(kv[1])
if err != nil {
@@ -118,31 +120,31 @@ func load(in io.Reader, conf *Config) error {
case helpvisible:
bv, err := strconv.ParseBool(kv[1])
if err != nil {
- return fmt.Errorf("line %d: %v", lineNo, err)
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.HelpVisible = bv
case colorscheme:
cs, err := colorschemes.FromName(conf.ConfigDir, kv[1])
if err != nil {
- return fmt.Errorf("line %d: %v", lineNo, err)
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.Colorscheme = cs
case updateinterval:
iv, err := strconv.Atoi(kv[1])
if err != nil {
- return err
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.UpdateInterval = time.Duration(iv)
case averagecpu:
bv, err := strconv.ParseBool(kv[1])
if err != nil {
- return fmt.Errorf("line %d: %v", lineNo, err)
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.AverageLoad = bv
case percpuload:
bv, err := strconv.ParseBool(kv[1])
if err != nil {
- return fmt.Errorf("line %d: %v", lineNo, err)
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.PercpuLoad = bv
case tempscale:
@@ -153,12 +155,12 @@ func load(in io.Reader, conf *Config) error {
conf.TempScale = 'F'
default:
conf.TempScale = 'C'
- return fmt.Errorf("invalid TempScale value %s", kv[1])
+ return fmt.Errorf(conf.Tr.Value("config.err.tempscale", kv[1]))
}
case statusbar:
bv, err := strconv.ParseBool(kv[1])
if err != nil {
- return fmt.Errorf("line %d: %v", lineNo, err)
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.Statusbar = bv
case netinterface:
@@ -168,7 +170,7 @@ func load(in io.Reader, conf *Config) error {
case maxlogsize:
iv, err := strconv.Atoi(kv[1])
if err != nil {
- return err
+ return fmt.Errorf(conf.Tr.Value("config.err.line", ln, err.Error()))
}
conf.MaxLogSize = int64(iv)
case export:
diff --git a/devices/devices.go b/devices/devices.go
index 7360578..8873ae5 100644
--- a/devices/devices.go
+++ b/devices/devices.go
@@ -2,6 +2,7 @@ package devices
import (
"log"
+ "github.com/jdkeke142/lingo-toml"
)
const (
@@ -15,6 +16,7 @@ var _shutdownFuncs []func() error
var _devs map[string][]string
var _defaults map[string][]string
var _startup []func(map[string]string) error
+var tr lingo.Translations
// RegisterShutdown stores a function to be called by gotop on exit, allowing
// extensions to properly release resources. Extensions should register a
@@ -86,3 +88,7 @@ func Devices(domain string, all bool) []string {
}
return _defaults[domain]
}
+
+func SetTr(tra lingo.Translations) {
+ tr = tra
+}
diff --git a/devices/smc.go b/devices/smc.go
index 4701a07..21931c4 100644
--- a/devices/smc.go
+++ b/devices/smc.go
@@ -1,8 +1,7 @@
-// Code generated by go-bindata.
-// sources:
-// data/smc.tsv
-// DO NOT EDIT!
+// Code generated by go-bindata. (@generated) DO NOT EDIT.
+ //Package devices generated by go-bindata.// sources:
+// devices/data/smc.tsv
package devices
import (
@@ -20,7 +19,7 @@ import (
func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
- return nil, fmt.Errorf("Read %q: %v", name, err)
+ return nil, fmt.Errorf("read %q: %v", name, err)
}
var buf bytes.Buffer
@@ -28,7 +27,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
clErr := gz.Close()
if err != nil {
- return nil, fmt.Errorf("Read %q: %v", name, err)
+ return nil, fmt.Errorf("read %q: %v", name, err)
}
if clErr != nil {
return nil, err
@@ -49,21 +48,32 @@ type bindataFileInfo struct {
modTime time.Time
}
+// Name return file name
func (fi bindataFileInfo) Name() string {
return fi.name
}
+
+// Size return file size
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
+
+// Mode return file mode
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
+
+// ModTime return file modify time
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
+
+// IsDir return file whether a directory
func (fi bindataFileInfo) IsDir() bool {
- return false
+ return fi.mode&os.ModeDir != 0
}
+
+// Sys return file is sys mode
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
@@ -83,7 +93,7 @@ func smcTsv() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "smc.tsv", size: 3398, mode: os.FileMode(420), modTime: time.Unix(1591711965, 0)}
+ info := bindataFileInfo{name: "smc.tsv", size: 3398, mode: os.FileMode(420), modTime: time.Unix(1592515411, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -182,6 +192,7 @@ type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
+
var _bintree = &bintree{nil, map[string]*bintree{
"smc.tsv": &bintree{smcTsv, map[string]*bintree{}},
}}
@@ -232,4 +243,3 @@ func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}
-
diff --git a/devices/temp.go b/devices/temp.go
index 247075a..87f534f 100644
--- a/devices/temp.go
+++ b/devices/temp.go
@@ -1,7 +1,5 @@
package devices
-//go:generate go-bindata -pkg devices -prefix data -o smc.go data
-
import (
"log"
)
@@ -19,7 +17,7 @@ func UpdateTemps(temps map[string]int) {
errs := f(temps)
if errs != nil {
for k, e := range errs {
- log.Printf("error updating temp for %s: %s", k, e)
+ log.Printf(tr.Value("error.recovfetch", "temp", k, e.Error()))
}
}
}
diff --git a/devices/temp_freebsd.go b/devices/temp_freebsd.go
index 3e659be..e87dcb3 100644
--- a/devices/temp_freebsd.go
+++ b/devices/temp_freebsd.go
@@ -13,7 +13,7 @@ import (
func init() {
if len(devs()) == 0 {
- log.Println("temp: no thermal sensors found")
+ log.Println(tr.Value("error.nodevfound", "thermal sensors"))
return
}
RegisterTemp(update)
@@ -58,13 +58,13 @@ func devs() []string {
// Check that thermal sensors are really available; they aren't in VMs
bs, err := exec.Command("sysctl", "-a").Output()
if err != nil {
- log.Printf("temp: failure to get system information %s", err.Error())
+ log.Printf(tr.Value("error.fatalfetch", "temp", err.Error()))
return []string{}
}
for k, _ := range sensorOIDS {
idx := strings.Index(string(bs), k)
if idx < 0 {
- log.Printf("temp: no device %s found", k)
+ log.Printf(tr.Value("error.nodevfound", k))
} else {
rv = append(rv, k)
}
diff --git a/go.mod b/go.mod
index 1e07313..bc7d8a4 100644
--- a/go.mod
+++ b/go.mod
@@ -4,9 +4,11 @@ require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/VictoriaMetrics/metrics v1.11.2
github.com/VividCortex/ewma v1.1.1
+ github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
github.com/distatus/battery v0.9.0
github.com/gizak/termui/v3 v3.1.0
github.com/go-ole/go-ole v1.2.4 // indirect
+ github.com/jdkeke142/lingo-toml v0.0.0-20200705162942-3520fe0dec06
github.com/mattn/go-runewidth v0.0.4
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0
diff --git a/go.sum b/go.sum
index 575a44b..f841c59 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,5 @@
+github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/VictoriaMetrics/metrics v1.11.2 h1:t/ceLP6SvagUqypCKU7cI7+tQn54+TIV/tGoxihHvx8=
@@ -6,21 +8,21 @@ github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdc
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd h1:XtfPmj9tQRilnrEmI1HjQhxXWRhEM+m8CACtaMJE/kM=
github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd/go.mod h1:vjcQJUZJYD3MeVGhtZXSMnCHfUNZxsyYzJt90eCYxK4=
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 h1:Yg2hDs4b13Evkpj42FU2idX2cVXVFqQSheXYKM86Qsk=
+github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21/go.mod h1:MgJyK38wkzZbiZSKeIeFankxxSA8gayko/nr5x5bgBA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distatus/battery v0.9.0 h1:8NS5o00/j3Oh2xgocA6pQROTp5guoR+s8CZlWzHC4QM=
github.com/distatus/battery v0.9.0/go.mod h1:gGO7GxHTi1zlRT+cAj8uGG0/8HFiqAeH0TJvoipnuPs=
-github.com/gizak/termui/v3 v3.0.0 h1:NYTUG6ig/sJK05O5FyhWemwlVPO8ilNpvS/PgRtrKAE=
-github.com/gizak/termui/v3 v3.0.0/go.mod h1:uinu2dMdtMI+FTIdEFUJQT5y+KShnhQRshvPblXq3lY=
github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc=
github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUA