Skip to content

Commit

Permalink
colorscheme: Add capability to include schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Jun 14, 2023
1 parent 0859f4a commit 6f232e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
15 changes: 13 additions & 2 deletions internal/config/colorscheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func LoadColorscheme(colorschemeName string) error {
// red background
func ParseColorscheme(text string) (map[string]tcell.Style, error) {
var err error
parser := regexp.MustCompile(`color-link\s+(\S*)\s+"(.*)"`)
colorParser := regexp.MustCompile(`color-link\s+(\S*)\s+"(.*)"`)
includeParser := regexp.MustCompile(`include:\s+"(.*)"`)

lines := strings.Split(text, "\n")

Expand All @@ -96,7 +97,17 @@ func ParseColorscheme(text string) (map[string]tcell.Style, error) {
continue
}

matches := parser.FindSubmatch([]byte(line))
matches := includeParser.FindSubmatch([]byte(line))
if len(matches) == 2 {
include := string(matches[1])
err = LoadColorscheme(include)
if err == nil {
c = Colorscheme
}
continue
}

matches = colorParser.FindSubmatch([]byte(line))
if len(matches) == 3 {
link := string(matches[1])
colors := string(matches[2])
Expand Down
32 changes: 1 addition & 31 deletions runtime/colorschemes/default.micro
Original file line number Diff line number Diff line change
@@ -1,31 +1 @@
color-link default "#F8F8F2,#282828"
color-link comment "#75715E,#282828"
color-link identifier "#66D9EF,#282828"
color-link constant "#AE81FF,#282828"
color-link constant.string "#E6DB74,#282828"
color-link constant.string.char "#BDE6AD,#282828"
color-link statement "#F92672,#282828"
color-link symbol.operator "#F92671,#282828"
color-link preproc "#CB4B16,#282828"
color-link type "#66D9EF,#282828"
color-link special "#A6E22E,#282828"
color-link underlined "#D33682,#282828"
color-link error "bold #CB4B16,#282828"
color-link todo "bold #D33682,#282828"
color-link hlsearch "#282828,#E6DB74"
color-link statusline "#282828,#F8F8F2"
color-link tabbar "#282828,#F8F8F2"
color-link indent-char "#505050,#282828"
color-link line-number "#AAAAAA,#323232"
color-link current-line-number "#AAAAAA,#282828"
color-link diff-added "#00AF00"
color-link diff-modified "#FFAF00"
color-link diff-deleted "#D70000"
color-link gutter-error "#CB4B16,#282828"
color-link gutter-warning "#E6DB74,#282828"
color-link cursor-line "#323232"
color-link color-column "#323232"
#No extended types; Plain brackets.
color-link type.extended "default"
#color-link symbol.brackets "default"
color-link symbol.tag "#AE81FF,#282828"
include: "monokai"
5 changes: 4 additions & 1 deletion runtime/help/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ Here's a list of subgroups used in micro's built-in syntax files.
* type.keyword (If you want a special highlight for keywords like `private`)

In the future, plugins may also be able to use color groups for styling.

Last but not least it's even possible to use `include:` followed by the
colorscheme name as string to include a different colorscheme within a new one.
Additionally the groups can then be extended or overwritten. The `default.micro`
theme can be seen as an example, which links to the chosen default colorscheme.

## Syntax files

Expand Down

0 comments on commit 6f232e5

Please # to comment.