mirror of https://github.com/cjbassi/gotop.git
Add custom colorscheme loading. Closes #55
This commit is contained in:
parent
bb36706e86
commit
db1b2fbc70
|
@ -68,8 +68,9 @@ go get github.com/cjbassi/gotop
|
||||||
|
|
||||||
### Colorschemes
|
### Colorschemes
|
||||||
|
|
||||||
gotop ships with a few colorschemes which can be set with the `-c` flag followed by the name of one.
|
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 [colorschemes](https://github.com/cjbassi/gotop/tree/master/colorschemes).
|
||||||
You can find all the colorschemes in [src/colorschemes](https://github.com/cjbassi/gotop/tree/master/src/colorschemes) and you can make your own by checking out the [template](https://github.com/cjbassi/gotop/blob/master/src/colorschemes/template.go). Colorschemes PR's are welcome!
|
|
||||||
|
To make a custom colorscheme, check out the [template](https://github.com/cjbassi/gotop/blob/master/colorschemes/template.go) for instructions and then use [default.json](https://github.com/cjbassi/gotop/blob/master/colorschemes/default.json) as a starter. Then you can put the file at `~/.config/gotop/{name}.json` and load it with `gotop -c {name}`. Colorschemes PR's are welcome!
|
||||||
|
|
||||||
### CLI Options
|
### CLI Options
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Example json file to put in `~/.config/gotop/{name}.json` and load with
|
||||||
|
// `gotop -c {name}`. MUST DELETE THESE COMMENTS in order to load.
|
||||||
|
{
|
||||||
|
"Fg": 7,
|
||||||
|
"Bg": -1,
|
||||||
|
|
||||||
|
"BorderLabel": 7,
|
||||||
|
"BorderLine": 6,
|
||||||
|
|
||||||
|
"CPULines": [4, 3, 2, 1, 5, 6, 7, 8],
|
||||||
|
|
||||||
|
"MainMem": 5,
|
||||||
|
"SwapMem": 11,
|
||||||
|
|
||||||
|
"ProcCursor": 4,
|
||||||
|
|
||||||
|
"Sparkline": 4,
|
||||||
|
|
||||||
|
"DiskBar": 7,
|
||||||
|
|
||||||
|
"TempLow": 2,
|
||||||
|
"TempHigh": 1
|
||||||
|
}
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
25
main.go
25
main.go
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -10,7 +12,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cjbassi/gotop/src/colorschemes"
|
"github.com/cjbassi/gotop/colorschemes"
|
||||||
w "github.com/cjbassi/gotop/src/widgets"
|
w "github.com/cjbassi/gotop/src/widgets"
|
||||||
ui "github.com/cjbassi/termui"
|
ui "github.com/cjbassi/termui"
|
||||||
"github.com/docopt/docopt-go"
|
"github.com/docopt/docopt-go"
|
||||||
|
@ -105,9 +107,30 @@ func handleColorscheme(cs string) {
|
||||||
case "default-dark":
|
case "default-dark":
|
||||||
colorscheme = colorschemes.DefaultDark
|
colorscheme = colorschemes.DefaultDark
|
||||||
default:
|
default:
|
||||||
|
colorscheme = getCustomColorscheme(cs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getCustomColorscheme tries to read a custom json colorscheme from
|
||||||
|
// {$XDG_CONFIG_HOME,~/.config}/gotop/{name}.json
|
||||||
|
func getCustomColorscheme(name string) colorschemes.Colorscheme {
|
||||||
|
xdg := os.Getenv("XDG_CONFIG_HOME")
|
||||||
|
if xdg == "" {
|
||||||
|
xdg = os.ExpandEnv("$HOME") + "/.config"
|
||||||
|
}
|
||||||
|
file := xdg + "/gotop/" + name + ".json"
|
||||||
|
dat, err := ioutil.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: colorscheme not recognized\n")
|
fmt.Fprintf(os.Stderr, "error: colorscheme not recognized\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
var colorscheme colorschemes.Colorscheme
|
||||||
|
err = json.Unmarshal(dat, &colorscheme)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error: could not parse colorscheme\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return colorscheme
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupGrid() {
|
func setupGrid() {
|
||||||
|
|
Loading…
Reference in New Issue