// The current colorscheme
var colorscheme Colorscheme
+// GetColor takes in a syntax group and returns the colorscheme's style for that group
+func GetColor(color string) tcell.Style {
+ st := defStyle
+ if color == "" {
+ return st
+ }
+ groups := strings.Split(color, ".")
+ if len(groups) > 1 {
+ curGroup := ""
+ for i, g := range groups {
+ if i != 0 {
+ curGroup += "."
+ }
+ curGroup += g
+ if style, ok := colorscheme[curGroup]; ok {
+ st = style
+ }
+ }
+ } else if style, ok := colorscheme[color]; ok {
+ st = style
+ } else {
+ st = StringToStyle(color)
+ }
+
+ return st
+}
+
// ColorschemeExists checks if a given colorscheme exists
func ColorschemeExists(colorschemeName string) bool {
return FindRuntimeFile(RTColorscheme, colorschemeName) != nil
// InitColorscheme picks and initializes the colorscheme when micro starts
func InitColorscheme() {
colorscheme = make(Colorscheme)
+ defStyle = tcell.StyleDefault.
+ Foreground(tcell.ColorDefault).
+ Background(tcell.ColorDefault)
if screen != nil {
- screen.SetStyle(tcell.StyleDefault.
- Foreground(tcell.ColorDefault).
- Background(tcell.ColorDefault))
+ // screen.SetStyle(defStyle)
}
LoadDefaultColorscheme()
TermMessage("Error loading colorscheme:", err)
} else {
colorscheme = ParseColorscheme(string(data))
-
- // Default style
- defStyle = tcell.StyleDefault.
- Foreground(tcell.ColorDefault).
- Background(tcell.ColorDefault)
-
- // There may be another default style defined in the colorscheme
- // In that case we should use that one
- if style, ok := colorscheme["default"]; ok {
- defStyle = style
- }
- if screen != nil {
- screen.SetStyle(defStyle)
- }
}
}
}
if link == "default" {
defStyle = style
}
+ if screen != nil {
+ // screen.SetStyle(defStyle)
+ }
} else {
fmt.Println("Color-link statement is not valid:", line)
}
// The 'extra' can be bold, reverse, or underline
func StringToStyle(str string) tcell.Style {
var fg, bg string
- split := strings.Split(str, ",")
+ spaceSplit := strings.Split(str, " ")
+ var split []string
+ if len(spaceSplit) > 1 {
+ split = strings.Split(spaceSplit[1], ",")
+ } else {
+ split = strings.Split(str, ",")
+ }
if len(split) > 1 {
fg, bg = split[0], split[1]
} else {
tcell.Color253, tcell.Color254, tcell.Color255,
}
- return colors[color]
+ if color >= 0 && color < len(colors) {
+ return colors[color]
+ }
+
+ return tcell.ColorDefault
}