Skip to content

Commit

Permalink
Fixes #92, configurable temps; help text & docs clean-up; versions ar…
Browse files Browse the repository at this point in the history
…e now built into binaries at compile time; clean up old extensions params; adds --list command; adds --write-config command; fixes bug in colorscheme loading; fixes bug in Colorschemes -- all had empty Name attrs; adds ability to list devices.
  • Loading branch information
xxxserxxx committed Apr 23, 2020
1 parent 3fcab5a commit 5ada531
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 87 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ jobs:
repository: xxxserxxx/gotop-linux
event-type: my-release
client-payload: '{"tag": "${{ steps.tag_name.outputs.tag }}"}'

# TODO: Build the plugins too
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ignore lines matching `/^#.*/` in layout files.
- Instructions for Gentoo (thanks @tormath1!)
- Graph labels that don't fit (vertically) in the window are now drawn in additional columns (#40)
- Adds ability to filter reported temperatures (#92)

### Changed

Expand All @@ -44,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Memory line colors were inconsistently assigned (#91)
- The disk code was truncating values instead of rounding (#90)
- Temperatures on Darwin were all over the place, and wrong (#48)
- Config file loading from `~/.config/gotop` wasn't working

## [3.5.1] - 2020-04-09

Expand Down
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,30 @@ Move `gotop` to somewhere in your `$PATH`.
- click to select process
- mouse wheel to scroll through processes

### Config file

Most command-line settings can be persisted into a configuration file. The config file is named `gotop.conf` and can be located in several places. The first place gotop will look is in the current directory; after this, the locations depend on the OS and distribution. On Linux using XDG, for instance, the home location of `~/.config/gotop/gotop.conf` is the second location. The last location is a system-wide global location, such as `/etc/gotop/gotop.conf`. The `-h` help command will print out all of the locations, in order. Command-line options override values in any config files, and only the first config file found is loaded.

A configuration file can be created using the `--write-config` command-line argument. This will try to place the config file in the home config directory (the second location), but if it's unable to do so it'll write a file to the current directory.

Config file changes can be made by combining command-line arguments with `--write-config`. For example, to persist the `solarized` theme, call:

```
gotop -c solarized --write-config
```

### Colorschemes

gotop ships with a few colorschemes which can be set with the `-c` flag followed by the name of one. You can find all the colorschemes in the [colorschemes folder](./colorschemes).

To make a custom colorscheme, check out the [template](./colorschemes/template.go) for instructions and then use [default.json](./colorschemes/default.json) as a starter. Then put the file at `~/.config/gotop/<name>.json` and load it with `gotop -c <name>`. Colorschemes PR's are welcome!

To list all built-in color schemes, call:

```
gotop --list colorschemes
```

### Layouts

gotop can parse and render layouts from a specification file. The format is
Expand Down Expand Up @@ -206,6 +224,49 @@ and these are separated by spaces.
Yes, you're clever enough to break the layout algorithm, but if you try to
build massive edifices, you're in for disappointment.
To list all built-in color schemes, call:
```
gotop --list layouts
```
### Device filtering
Some devices have quite a number of data points; on OSX, for instance, there are dozens of temperature readings. These can be filtered through a configuration file. There is no command-line argument for this filter.
The list will grow, but for now the only device that supports filtering is the temperature widget. The configuration entry is called `temperature`, and it contains an exact-match list of comma-separated values with no spaces. To see the list of valid values, run gotop with the `--list devices` command. Gotop will print out the type of device and the legal values. For example, on Linux:
```
$ gotop --list devices
Temperatures:
acpitz
nvme_composite
nvme_sensor1
nvme_sensor2
pch_cannonlake
coretemp_packageid0
coretemp_core0
coretemp_core1
coretemp_core2
coretemp_core3
ath10k_hwmon
```
You might then add the following line to the config file. First, find where gotop looks for config files:
```
$ gotop -h | tail -n 6
Colorschemes & layouts that are not built-in are searched for (in order) in:
/home/USER/workspace/gotop.d/gotop, /home/USER/.config/gotop, /etc/xdg/gotop
The first path in this list is always the cwd. The config file
'gotop.config' can also reside in one of these directories.

Log files are stored in /home/ser/.cache/gotop/errors.log
```
So you might use `/home/YOU/.config/gotop.conf`, and add (or modify) this line:
```
temperatures=acpitz,coretemp_core0,ath10k_hwmon
```
This will cause the temp widget to show only four of the eleven temps.
### CLI Options
Run `gotop -h` to see the list of all command line options.
Expand Down
120 changes: 68 additions & 52 deletions cmd/gotop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"path/filepath"
"sort"
"strconv"
"strings"
"syscall"
Expand All @@ -20,6 +21,7 @@ import (

"github.com/xxxserxxx/gotop/v3"
"github.com/xxxserxxx/gotop/v3/colorschemes"
"github.com/xxxserxxx/gotop/v3/devices"
"github.com/xxxserxxx/gotop/v3/layout"
"github.com/xxxserxxx/gotop/v3/logging"
w "github.com/xxxserxxx/gotop/v3/widgets"
Expand All @@ -37,8 +39,8 @@ const (
)

var (
// TODO: Set this at compile time; having to check this in sucks.
Version = "3.6.dev"
Version = "0.0.0"
BuildDate = "Hadean"
conf gotop.Config
help *w.HelpMenu
bar *w.StatusBar
Expand All @@ -48,17 +50,14 @@ var (

// TODO: Add tab completion for Linux https://gist.github.com/icholy/5314423
// TODO: state:merge #135 linux console font (cmatsuoka/console-font)
// TODO: state:deferred 157 FreeBSD fixes & Nvidia GPU support (kraust/master). Significant CPU use impact for NVidia changes.
// TODO: Virtual devices from Prometeus metrics @feature
// TODO: Abstract out the UI toolkit. mum4k/termdash, VladimirMarkelov/clui, gcla/gowid, rivo/tview, marcusolsson/tui-go might work better for some OS/Archs. Performance/memory use comparison would be interesting.
// TODO: Add fans
func parseArgs(conf *gotop.Config) error {
cds := conf.ConfigDir.QueryFolders(configdir.All)
cpaths := make([]string, len(cds))
for i, p := range cds {
cpaths[i] = p.Path
}
usage := fmt.Sprintf(`
usage := fmt.Sprintln(`
Usage: gotop [options]
Options:
Expand All @@ -77,40 +76,15 @@ Options:
-l, --layout=NAME Name of layout spec file for the UI. Looks first in $XDG_CONFIG_HOME/gotop, then as a path. Use "-" to pipe.
-i, --interface=NAME Select network interface [default: all]. Several interfaces can be defined using comma separated values. Interfaces can also be ignored using !
-x, --export=PORT Enable metrics for export on the specified port.
-X, --extensions=NAMES Enables the listed extensions. This is a comma-separated list without the .so suffix. The current and config directories will be searched.
--mbps Net widget shows mb(its)ps for RX/TX instead of scaled bytes per second.
--test Runs tests and exits with success/failure code.
--print-paths List out the paths that gotop will look for gotop.conf, layouts, color schemes, and extensions.
--print-keys Show the keyboard bindings.
Built-in layouts:
default
minimal
battery
kitchensink
Colorschemes:
default
default-dark (for white background)
solarized
solarized16-dark
solarized16-light
monokai
vice
Colorschemes and layouts that are not built-in are searched for (in order) in:
%s
The first path in this list is always the cwd.
Log files are stored in %s
`, strings.Join(cpaths, ", "), filepath.Join(conf.ConfigDir.QueryCacheFolder().Path, logging.LOGFILE))

var err error
conf.Colorscheme, err = colorschemes.FromName(conf.ConfigDir, "default")
if err != nil {
return err
}
--list <devices|layouts|colorschemes|paths|keys>
devices: Prints out device names for widgets supporting filters.
layouts: Lists build-in layouts
colorschemes: Lists built-in colorschemes
paths: List out the paths that gotop will look for gotop.conf, layouts, and color schemes.
keys: Show the keyboard bindings.
--write-config Write out a sample config file, either to the home config location, or current directory. Command-line arguments specificed at the same time will overwrite values in the config file.`)

args, err := docopt.ParseArgs(usage, os.Args[1:], Version)
if err != nil {
Expand All @@ -127,6 +101,7 @@ Log files are stored in %s
}
conf.Colorscheme = cs
}

if args["--averagecpu"].(bool) {
conf.AverageLoad, _ = args["--averagecpu"].(bool)
}
Expand Down Expand Up @@ -166,10 +141,6 @@ Log files are stored in %s
if val, _ := args["--interface"]; val != nil {
conf.NetInterface, _ = args["--interface"].(string)
}
if val, _ := args["--extensions"]; val != nil {
exs, _ := args["--extensions"].(string)
conf.Extensions = strings.Split(exs, ",")
}
if val, _ := args["--test"]; val != nil {
conf.Test = val.(bool)
}
Expand All @@ -189,16 +160,35 @@ Log files are stored in %s
if args["--mbps"].(bool) {
conf.Mbps = true
}
if args["--print-paths"].(bool) {
paths := make([]string, 0)
for _, d := range conf.ConfigDir.QueryFolders(configdir.All) {
paths = append(paths, d.Path)
}
fmt.Println(strings.Join(paths, "\n"))
os.Exit(0)
}
if args["--print-keys"].(bool) {
fmt.Println(`
if val, _ := args["--list"]; val != nil {
switch val {
case "layouts":
fmt.Println("Built-in layouts:")
fmt.Println("\tdefault")
fmt.Println("\tminimal")
fmt.Println("\tbattery")
fmt.Println("\tkitchensink")
case "colorschemes":
fmt.Println("Built-in colorschemes:")
fmt.Println("\tdefault")
fmt.Println("\tdefault-dark (for white background)")
fmt.Println("\tsolarized")
fmt.Println("\tsolarized16-dark")
fmt.Println("\tsolarized16-light")
fmt.Println("\tmonokai")
fmt.Println("\tvice")
case "paths":
fmt.Println("Loadable colorschemes & layouts, and the config file, are searched for, in order:")
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))
case "devices":
listDevices()
case "keys":
fmt.Println(`
Quit: q or <C-c>
Process navigation:
k and <Up>: up
Expand Down Expand Up @@ -227,6 +217,19 @@ CPU and Mem graph scaling:
h: scale in
l: scale out
?: toggles keybind help menu`)
default:
fmt.Printf("Unknown option \"%s\"; try layouts, colorschemes, or devices\n", val)
os.Exit(1)
}
os.Exit(0)
}
if args["--write-config"].(bool) {
path, err := conf.Write()
if err != nil {
fmt.Printf("Failed to write configuration file: %s\n", err)
os.Exit(1)
}
fmt.Printf("Config written to %s\n", path)
os.Exit(0)
}

Expand Down Expand Up @@ -437,9 +440,11 @@ func makeConfig() gotop.Config {
MaxLogSize: 5000000,
Layout: "default",
}
conf.Colorscheme, _ = colorschemes.FromName(conf.ConfigDir, "default")
return conf
}

// TODO: Add fans
// TODO: mpd visualizer widget
func main() {
// This is just to make sure gotop returns a useful exit code, but also
Expand Down Expand Up @@ -567,3 +572,14 @@ func runTests(conf gotop.Config) int {
fmt.Printf("PASS")
return 0
}

func listDevices() {
ms := devices.Domains
sort.Strings(ms)
for _, m := range ms {
fmt.Printf("%s:\n", m)
for _, d := range devices.Devices(m) {
fmt.Printf("\t%s\n", d)
}
}
}
1 change: 1 addition & 0 deletions colorschemes/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func register(name string, c Colorscheme) {
if registry == nil {
registry = make(map[string]Colorscheme)
}
c.Name = name
registry[name] = c
}

Expand Down
Loading

0 comments on commit 5ada531

Please sign in to comment.