summaryrefslogtreecommitdiffstats
path: root/colorschemes
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-02-17 11:40:16 -0600
committerSean E. Russell <ser@ser1.net>2020-02-17 11:40:16 -0600
commit2a533986815836ac65c2b03d1f9c4c508e5b98a9 (patch)
tree03d18ab237434820066eb82025f539ce1bfdbc56 /colorschemes
parent3fc3d1e18ed1f80444d037f34769841f4a7e37d9 (diff)
parent10e3b7afbc53fe68b3c9ec0dd8ddff4e15fba9e4 (diff)
Adds log rotation, config file support, and refactoring. Colorschemes are self-registered. Merge remote-tracking branch 'jrswab/configFile111' into config_file; drastically refactored, and am not sure how much original code from the patch was used.
Diffstat (limited to 'colorschemes')
-rw-r--r--colorschemes/default.go30
-rw-r--r--colorschemes/default_dark.go30
-rw-r--r--colorschemes/monokai.go30
-rw-r--r--colorschemes/nord.go34
-rw-r--r--colorschemes/registry.go43
-rw-r--r--colorschemes/solarized.go30
-rw-r--r--colorschemes/solarized16-dark.go30
-rw-r--r--colorschemes/solarized16-light.go30
-rw-r--r--colorschemes/vice.go30
9 files changed, 173 insertions, 114 deletions
diff --git a/colorschemes/default.go b/colorschemes/default.go
index de65c22..dc6c6b2 100644
--- a/colorschemes/default.go
+++ b/colorschemes/default.go
@@ -1,25 +1,27 @@
package colorschemes
-var Default = Colorscheme{
- Fg: 7,
- Bg: -1,
+func init() {
+ register("default", Colorscheme{
+ Fg: 7,
+ Bg: -1,
- BorderLabel: 7,
- BorderLine: 6,
+ BorderLabel: 7,
+ BorderLine: 6,
- CPULines: []int{4, 3, 2, 1, 5, 6, 7, 8},
+ CPULines: []int{4, 3, 2, 1, 5, 6, 7, 8},
- BattLines: []int{4, 3, 2, 1, 5, 6, 7, 8},
+ BattLines: []int{4, 3, 2, 1, 5, 6, 7, 8},
- MainMem: 5,
- SwapMem: 11,
+ MainMem: 5,
+ SwapMem: 11,
- ProcCursor: 4,
+ ProcCursor: 4,
- Sparkline: 4,
+ Sparkline: 4,
- DiskBar: 7,
+ DiskBar: 7,
- TempLow: 2,
- TempHigh: 1,
+ TempLow: 2,
+ TempHigh: 1,
+ })
}
diff --git a/colorschemes/default_dark.go b/colorschemes/default_dark.go
index 6070985..7ddb5f7 100644
--- a/colorschemes/default_dark.go
+++ b/colorschemes/default_dark.go
@@ -1,25 +1,27 @@
package colorschemes
-var DefaultDark = Colorscheme{
- Fg: 235,
- Bg: -1,
+func init() {
+ register("defaultdark", Colorscheme{
+ Fg: 235,
+ Bg: -1,
- BorderLabel: 235,
- BorderLine: 6,
+ BorderLabel: 235,
+ BorderLine: 6,
- CPULines: []int{4, 3, 2, 1, 5, 6, 7, 8},
+ CPULines: []int{4, 3, 2, 1, 5, 6, 7, 8},
- BattLines: []int{4, 3, 2, 1, 5, 6, 7, 8},
+ BattLines: []int{4, 3, 2, 1, 5, 6, 7, 8},
- MainMem: 5,
- SwapMem: 3,
+ MainMem: 5,
+ SwapMem: 3,
- ProcCursor: 33,
+ ProcCursor: 33,
- Sparkline: 4,
+ Sparkline: 4,
- DiskBar: 252,
+ DiskBar: 252,
- TempLow: 2,
- TempHigh: 1,
+ TempLow: 2,
+ TempHigh: 1,
+ })
}
diff --git a/colorschemes/monokai.go b/colorschemes/monokai.go
index 445f054..cd0471c 100644
--- a/colorschemes/monokai.go
+++ b/colorschemes/monokai.go
@@ -1,25 +1,27 @@
package colorschemes
-var Monokai = Colorscheme{
- Fg: 249,
- Bg: -1,
+func init() {
+ register("monokai", Colorscheme{
+ Fg: 249,
+ Bg: -1,
- BorderLabel: 249,
- BorderLine: 239,
+ BorderLabel: 249,
+ BorderLine: 239,
- CPULines: []int{81, 70, 208, 197, 249, 141, 221, 186},
+ CPULines: []int{81, 70, 208, 197, 249, 141, 221, 186},
- BattLines: []int{81, 70, 208, 197, 249, 141, 221, 186},
+ BattLines: []int{81, 70, 208, 197, 249, 141, 221, 186},
- MainMem: 208,
- SwapMem: 186,
+ MainMem: 208,
+ SwapMem: 186,
- ProcCursor: 197,
+ ProcCursor: 197,
- Sparkline: 81,
+ Sparkline: 81,
- DiskBar: 102,
+ DiskBar: 102,
- TempLow: 70,
- TempHigh: 208,
+ TempLow: 70,
+ TempHigh: 208,
+ })
}
diff --git a/colorschemes/nord.go b/colorschemes/nord.go
index f493e40..b6d4b50 100644
--- a/colorschemes/nord.go
+++ b/colorschemes/nord.go
@@ -11,28 +11,30 @@
package colorschemes
-var Nord = Colorscheme{
- Name: "A Nord Approximation",
- Author: "@jrswab",
- Fg: 254, // lightest
- Bg: -1,
+func init() {
+ register("nord", Colorscheme{
+ Name: "A Nord Approximation",
+ Author: "@jrswab",
+ Fg: 254, // lightest
+ Bg: -1,
- BorderLabel: 254,
- BorderLine: 96, // Purple
+ BorderLabel: 254,
+ BorderLine: 96, // Purple
- CPULines: []int{4, 3, 2, 1, 5, 6, 7, 8},
+ CPULines: []int{4, 3, 2, 1, 5, 6, 7, 8},
- BattLines: []int{4, 3, 2, 1, 5, 6, 7, 8},
+ BattLines: []int{4, 3, 2, 1, 5, 6, 7, 8},
- MainMem: 172, // Orange
- SwapMem: 221, // yellow
+ MainMem: 172, // Orange
+ SwapMem: 221, // yellow
- ProcCursor: 31, // blue (nord9)
+ ProcCursor: 31, // blue (nord9)
- Sparkline: 31,
+ Sparkline: 31,
- DiskBar: 254,
+ DiskBar: 254,
- TempLow: 64, // green
- TempHigh: 167, // red
+ TempLow: 64, // green
+ TempHigh: 167, // red
+ })
}
diff --git a/colorschemes/registry.go b/colorschemes/registry.go
new file mode 100644
index 0000000..97e2bb0
--- /dev/null
+++ b/colorschemes/registry.go
@@ -0,0 +1,43 @@
+package colorschemes
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "path/filepath"
+)
+
+var registry map[string]Colorscheme
+
+func FromName(confDir string, c string) (Colorscheme, error) {
+ cs, ok := registry[c]
+ if !ok {
+ cs, err := getCustomColorscheme(confDir, c)
+ if err != nil {
+ return cs, err
+ }
+ }
+ return cs, nil
+}
+
+func register(name string, c Colorscheme) {
+ if registry == nil {
+ registry = make(map[string]Colorscheme)
+ }
+ registry[name] = c
+}
+
+// getCustomColorscheme tries to read a custom json colorscheme from <configDir>/<name>.json
+func getCustomColorscheme(confDir string, name string) (Colorscheme, error) {
+ var cs Colorscheme
+ filePath := filepath.Join(confDir, name+".json")
+ dat, err := ioutil.ReadFile(filePath)
+ if err != nil {
+ return cs, fmt.Errorf("failed to read colorscheme file: %v", err)
+ }
+ err = json.Unmarshal(dat, &cs)
+ if err != nil {
+ return cs, fmt.Errorf("failed to parse colorscheme file: %v", err)
+ }
+ return cs, nil
+}
diff --git a/colorschemes/solarized.go b/colorschemes/solarized.go
index 5968310..48d67b0 100644
--- a/colorschemes/solarized.go
+++ b/colorschemes/solarized.go
@@ -3,26 +3,28 @@ package colorschemes
// This is a neutral version of the Solarized 256-color palette. The exception
// is that the one grey color uses the average of base0 and base00, which are
// already middle of the road.
-var Solarized = Colorscheme{
- Fg: -1,
- Bg: -1,
+func init() {
+ register("solarized", Colorscheme{
+ Fg: -1,
+ Bg: -1,
- BorderLabel: -1,
- BorderLine: 37,
+ BorderLabel: -1,
+ BorderLine: 37,
- CPULines: []int{61, 33, 37, 64, 125, 160, 166, 136},
+ CPULines: []int{61, 33, 37, 64, 125, 160, 166, 136},
- BattLines: []int{61, 33, 37, 64, 125, 160, 166, 136},
+ BattLines: []int{61, 33, 37, 64, 125, 160, 166, 136},
- MainMem: 125,
- SwapMem: 166,
+ MainMem: 125,
+ SwapMem: 166,
- ProcCursor: 136,
+ ProcCursor: 136,
- Sparkline: 33,
+ Sparkline: 33,
- DiskBar: 243,
+ DiskBar: 243,
- TempLow: 64,
- TempHigh: 160,
+ TempLow: 64,
+ TempHigh: 160,
+ })
}
diff --git a/colorschemes/solarized16-dark.go b/colorschemes/solarized16-dark.go
index f8cdab7..202dbab 100644
--- a/colorschemes/solarized16-dark.go
+++ b/colorschemes/solarized16-dark.go
@@ -2,26 +2,28 @@ package colorschemes
// This scheme assumes the terminal already uses Solarized. Only DiskBar is
// different between dark/light.
-var Solarized16Dark = Colorscheme{
- Fg: -1,
- Bg: -1,
+func init() {
+ register("solarized16dark", Colorscheme{
+ Fg: -1,
+ Bg: -1,
- BorderLabel: -1,
- BorderLine: 6,
+ BorderLabel: -1,
+ BorderLine: 6,
- CPULines: []int{13, 4, 6, 2, 5, 1, 9, 3},
+ CPULines: []int{13, 4, 6, 2, 5, 1, 9, 3},
- BattLines: []int{13, 4, 6, 2, 5, 1, 9, 3},
+ BattLines: []int{13, 4, 6, 2, 5, 1, 9, 3},
- MainMem: 5,
- SwapMem: 9,
+ MainMem: 5,
+ SwapMem: 9,
- ProcCursor: 4,
+ ProcCursor: 4,
- Sparkline: 4,
+ Sparkline: 4,
- DiskBar: 12, // base0
+ DiskBar: 12, // base0
- TempLow: 2,
- TempHigh: 1,
+ TempLow: 2,
+ TempHigh: 1,
+ })
}
diff --git a/colorschemes/solarized16-light.go b/colorschemes/solarized16-light.go
index 8426a95..351fe4e 100644
--- a/colorschemes/solarized16-light.go
+++ b/colorschemes/solarized16-light.go
@@ -2,26 +2,28 @@ package colorschemes
// This scheme assumes the terminal already uses Solarized. Only DiskBar is
// different between dark/light.
-var Solarized16Light = Colorscheme{
- Fg: -1,
- Bg: -1,
+func init() {
+ register("solarized16light", Colorscheme{
+ Fg: -1,
+ Bg: -1,
- BorderLabel: -1,
- BorderLine: 6,
+ BorderLabel: -1,
+ BorderLine: 6,
- CPULines: []int{13, 4, 6, 2, 5, 1, 9, 3},
+ CPULines: []int{13, 4, 6, 2, 5, 1, 9, 3},
- BattLines: []int{13, 4, 6, 2, 5, 1, 9, 3},
+ BattLines: []int{13, 4, 6, 2, 5, 1, 9, 3},
- MainMem: 5,
- SwapMem: 9,
+ MainMem: 5,
+ SwapMem: 9,
- ProcCursor: 4,
+ ProcCursor: 4,
- Sparkline: 4,
+ Sparkline: 4,
- DiskBar: 11, // base00
+ DiskBar: 11, // base00
- TempLow: 2,
- TempHigh: 1,
+ TempLow: 2,
+ TempHigh: 1,
+ })
}
diff --git a/colorschemes/vice.go b/colorschemes/vice.go
index 23fa02a..8bd2545 100644
--- a/colorschemes/vice.go
+++ b/colorschemes/vice.go
@@ -1,25 +1,27 @@
package colorschemes
-var Vice = Colorscheme{
- Fg: 231,
- Bg: -1,
+func init() {
+ register("vice", Colorscheme{
+ Fg: 231,
+ Bg: -1,
- BorderLabel: 123,
- BorderLine: 102,
+ BorderLabel: 123,
+ BorderLine: 102,
- CPULines: []int{212, 218, 123, 159, 229, 158, 183, 146},
+ CPULines: []int{212, 218, 123, 159, 229, 158, 183, 146},
- BattLines: []int{212, 218, 123, 159, 229, 158, 183, 146},
+ BattLines: []int{212, 218, 123, 159, 229, 158, 183, 146},
- MainMem: 201,
- SwapMem: 97,
+ MainMem: 201,
+ SwapMem: 97,
- ProcCursor: 159,
+ ProcCursor: 159,
- Sparkline: 183,
+ Sparkline: 183,
- DiskBar: 158,
+ DiskBar: 158,
- TempLow: 49,
- TempHigh: 197,
+ TempLow: 49,
+ TempHigh: 197,
+ })
}