-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#93): add support for color scheme configuration
- Loading branch information
Showing
16 changed files
with
391 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
default: | ||
background: "#161616" | ||
foreground: "#c7c7c7" | ||
foreground2: "#FFFFFF" | ||
|
||
finder: | ||
cursor: "#8B0000" | ||
title: "#E9CE58" | ||
match: "#90EE90" | ||
highlight: | ||
background: "#3A3A3A" | ||
foreground: "#FFFFFF" | ||
match: "#E0FFFF" | ||
|
||
navigation: | ||
top: | ||
background: "#5F875f" | ||
foreground1: "#FFFFFF" | ||
foreground2: "#151515" | ||
bottom: | ||
background: "#5F87AF" | ||
foreground1: "#FFFFFF" | ||
foreground2: "#151515" | ||
|
||
details: | ||
foreground: "#696969" | ||
|
||
boards: | ||
title: | ||
foreground: "#ecce58" | ||
headers: | ||
background: "#5F87AF" | ||
foreground: "#FFFFFF" | ||
column: | ||
background: "#232323" | ||
foreground: "#ffffff" | ||
highlight: | ||
background: "#484848" | ||
foreground: "#ffffff" | ||
selection: | ||
background: "#8B0000" | ||
foreground: "#ffffff" | ||
|
||
spinner: | ||
accent: "#FF0000" | ||
|
||
alerts: | ||
success: | ||
background: "#F5F5F5" | ||
foreground: "#006400" | ||
error: | ||
background: "#F5F5F5" | ||
foreground: "#8B0000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gdamore/tcell/v2" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var ( | ||
schemeMap map[string]interface{} | ||
colorsMap = map[string]tcell.Color{} | ||
) | ||
|
||
func Color(c string) tcell.Color { | ||
if color, ok := colorsMap[c]; ok { | ||
return color | ||
} | ||
parts := strings.Split(c, ".") | ||
var t interface{} | ||
var hex string | ||
t = schemeMap | ||
for _, p := range parts { | ||
if m, ok := t.(map[string]interface{}); ok { | ||
t = m[p] | ||
} | ||
if h, ok := t.(string); ok { | ||
hex = h | ||
} | ||
} | ||
color := tcell.GetColor(hex) | ||
colorsMap[c] = color | ||
return color | ||
} | ||
|
||
func MustLoadColorScheme() map[string]interface{} { | ||
d, _ := os.UserHomeDir() | ||
p := fmt.Sprintf("%s/.fjira/colors.yml", d) | ||
b, err := os.ReadFile(p) | ||
if err != nil { | ||
schemeMap = parseYMLStr(defaultColorsYML()) | ||
return schemeMap | ||
} | ||
schemeMap = parseYMLStr(string(b)) | ||
return schemeMap | ||
} | ||
|
||
func parseYMLStr(y string) map[string]interface{} { | ||
var yml map[string]interface{} | ||
err := yaml.Unmarshal([]byte(y), &yml) | ||
if err != nil { | ||
Error(err.Error()) | ||
return map[string]interface{}{} | ||
} | ||
return yml | ||
} | ||
|
||
func defaultColorsYML() string { | ||
return ` | ||
default: | ||
background: "#161616" | ||
foreground: "#c7c7c7" | ||
foreground2: "#FFFFFF" | ||
finder: | ||
cursor: "#8B0000" | ||
title: "#E9CE58" | ||
match: "#90EE90" | ||
highlight: | ||
background: "#3A3A3A" | ||
foreground: "#FFFFFF" | ||
match: "#E0FFFF" | ||
navigation: | ||
top: | ||
background: "#5F875f" | ||
foreground1: "#FFFFFF" | ||
foreground2: "#151515" | ||
bottom: | ||
background: "#5F87AF" | ||
foreground1: "#FFFFFF" | ||
foreground2: "#151515" | ||
details: | ||
foreground: "#696969" | ||
boards: | ||
title: | ||
foreground: "#ecce58" | ||
headers: | ||
background: "#5F875f" | ||
foreground: "#FFFFFF" | ||
column: | ||
background: "#232323" | ||
foreground: "#ffffff" | ||
highlight: | ||
background: "#484848" | ||
foreground: "#ffffff" | ||
selection: | ||
background: "#8B0000" | ||
foreground: "#ffffff" | ||
spinner: | ||
accent: "#FF0000" | ||
alerts: | ||
success: | ||
background: "#F5F5F5" | ||
foreground: "#006400" | ||
error: | ||
background: "#F5F5F5" | ||
foreground: "#8B0000" | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
os2 "github.com/mk-5/fjira/internal/os" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestColor(t *testing.T) { | ||
MustLoadColorScheme() | ||
|
||
type args struct { | ||
c string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want int32 | ||
}{ | ||
{"should get color from default colors", args{c: "navigation.top.background"}, 6260575}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, Color(tt.args.c).Hex(), "Color(%v)", tt.args.c) | ||
}) | ||
} | ||
} | ||
|
||
func TestMustLoadColorScheme(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
}{ | ||
{"should load color scheme from user directory"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// given | ||
f := ` | ||
navigation: | ||
top: | ||
background: "#0000FF" | ||
foreground1: "#EEEEEE" | ||
` | ||
tempDir := t.TempDir() | ||
_ = os2.SetUserHomeDir(tempDir) | ||
_ = os.MkdirAll(fmt.Sprintf("%s/.fjira", tempDir), os.ModePerm) | ||
p := fmt.Sprintf("%s/.fjira/colors.yml", tempDir) | ||
err := os.WriteFile(p, []byte(f), 0644) | ||
assert.Nil(t, err) | ||
|
||
// when | ||
MustLoadColorScheme() | ||
|
||
// then | ||
assert.Equalf(t, int32(255), Color("navigation.top.background").Hex(), "MustLoadColorScheme()") | ||
assert.Equalf(t, int32(15658734), Color("navigation.top.foreground1").Hex(), "MustLoadColorScheme()") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.