summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-09-18 13:42:49 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2018-09-18 13:42:49 -0700
commitdb1b2fbc70536b0b7ad8f36b1fdee297094eb139 (patch)
tree8992fe9396ce0dbeafde99ecd671eb5ae21d78a7
parentbb36706e866475e65f1629466e0ea202223afc01 (diff)
Add custom colorscheme loading. Closes #55
-rw-r--r--README.md5
-rw-r--r--colorschemes/default.go (renamed from src/colorschemes/default.go)0
-rw-r--r--colorschemes/default.json23
-rw-r--r--colorschemes/default_dark.go (renamed from src/colorschemes/default_dark.go)0
-rw-r--r--colorschemes/monokai.go (renamed from src/colorschemes/monokai.go)0
-rw-r--r--colorschemes/monokai.png (renamed from src/colorschemes/monokai.png)bin93386 -> 93386 bytes
-rw-r--r--colorschemes/solarized.go (renamed from src/colorschemes/solarized.go)0
-rw-r--r--colorschemes/solarized.png (renamed from src/colorschemes/solarized.png)bin88930 -> 88930 bytes
-rw-r--r--colorschemes/template.go (renamed from src/colorschemes/template.go)0
-rw-r--r--main.go25
10 files changed, 50 insertions, 3 deletions
diff --git a/README.md b/README.md
index e1062ac..690179b 100644
--- a/README.md
+++ b/README.md
@@ -68,8 +68,9 @@ go get github.com/cjbassi/gotop
### 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 [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!
+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).
+
+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
diff --git a/src/colorschemes/default.go b/colorschemes/default.go
index 48db2d3..48db2d3 100644
--- a/src/colorschemes/default.go
+++ b/colorschemes/default.go
diff --git a/colorschemes/default.json b/colorschemes/default.json
new file mode 100644
index 0000000..5d26a8b
--- /dev/null
+++ b/colorschemes/default.json
@@ -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
+}
diff --git a/src/colorschemes/default_dark.go b/colorschemes/default_dark.go
index 15f7137..15f7137 100644
--- a/src/colorschemes/default_dark.go
+++ b/colorschemes/default_dark.go
diff --git a/src/colorschemes/monokai.go b/colorschemes/monokai.go
index b3dbc23..b3dbc23 100644
--- a/src/colorschemes/monokai.go
+++ b/colorschemes/monokai.go
diff --git a/src/colorschemes/monokai.png b/colorschemes/monokai.png
index 468d2b2..468d2b2 100644
--- a/src/colorschemes/monokai.png
+++ b/colorschemes/monokai.png
Binary files differ
diff --git a/src/colorschemes/solarized.go b/colorschemes/solarized.go
index 2ead4df..2ead4df 100644
--- a/src/colorschemes/solarized.go
+++ b/colorschemes/solarized.go
diff --git a/src/colorschemes/solarized.png b/colorschemes/solarized.png
index b697919..b697919 100644
--- a/src/colorschemes/solarized.png
+++ b/colorschemes/solarized.png
Binary files differ
diff --git a/src/colorschemes/template.go b/colorschemes/template.go
index d303e4b..d303e4b 100644
--- a/src/colorschemes/template.go
+++ b/colorschemes/template.go
diff --git a/main.go b/main.go
index a3956ed..8021ae5 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,9 @@
package main
import (
+ "encoding/json"
"fmt"
+ "io/ioutil"
"os"
"os/signal"
"sort"
@@ -10,7 +12,7 @@ import (
"syscall"
"time"
- "github.com/cjbassi/gotop/src/colorschemes"
+ "github.com/cjbassi/gotop/colorschemes"
w "github.com/cjbassi/gotop/src/widgets"
ui "github.com/cjbassi/termui"
"github.com/docopt/docopt-go"
@@ -105,9 +107,30 @@ func handleColorscheme(cs string) {
case "default-dark":
colorscheme = colorschemes.DefaultDark
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")
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() {