Revise example.

This commit is contained in:
Jesse Portnoy
2023-07-18 17:18:48 +01:00
parent 21c71649f6
commit 57b5bfb135
2 changed files with 99 additions and 57 deletions
+40 -17
View File
@@ -22,12 +22,11 @@ func main() {
var syn_dir string
if gopath == "" {
syn_dir = "/etc/highlight"
syn_dir = os.Getenv("HOME") + "/.config/zaje/syntax_files"
} else {
syn_dir = gopath + "/src/github.com/jessp01/gohighlight/syntax_files"
}
syn_dir = os.Getenv("SYNDIR")
var defs []*highlight.Def
err := highlight.ParseSyntaxFiles(syn_dir, &defs)
if err != nil {
@@ -53,28 +52,51 @@ func main() {
colN := 0
for _, c := range l {
if group, ok := matches[lineN][colN]; ok {
// There are more possible groups available than just these ones
if group == highlight.Groups["statement"] {
switch group {
case highlight.Groups["statement"]:
fallthrough
case highlight.Groups["green"]:
color.Set(color.FgGreen)
} else if group == highlight.Groups["identifier"] {
color.Set(color.FgBlue)
} else if group == highlight.Groups["preproc"] {
case highlight.Groups["identifier"]:
fallthrough
case highlight.Groups["blue"]:
color.Set(color.FgHiBlue)
case highlight.Groups["preproc"]:
//fallthrough
//case highlight.Groups["high.red"]:
color.Set(color.FgHiRed)
} else if group == highlight.Groups["special"] {
case highlight.Groups["special"]:
fallthrough
case highlight.Groups["red"]:
color.Set(color.FgRed)
} else if group == highlight.Groups["constant.string"] {
case highlight.Groups["constant.string"]:
fallthrough
case highlight.Groups["constant"]:
fallthrough
case highlight.Groups["constant.number"]:
fallthrough
case highlight.Groups["cyan"]:
color.Set(color.FgCyan)
} else if group == highlight.Groups["constant"] {
color.Set(color.FgCyan)
} else if group == highlight.Groups["constant.specialChar"] {
case highlight.Groups["constant.specialChar"]:
fallthrough
case highlight.Groups["magenta"]:
color.Set(color.FgHiMagenta)
} else if group == highlight.Groups["type"] {
case highlight.Groups["type"]:
fallthrough
case highlight.Groups["yellow"]:
color.Set(color.FgYellow)
} else if group == highlight.Groups["constant.number"] {
color.Set(color.FgCyan)
} else if group == highlight.Groups["comment"] {
case highlight.Groups["comment"]:
fallthrough
case highlight.Groups["high.green"]:
color.Set(color.FgHiGreen)
} else {
default:
color.Unset()
}
}
@@ -87,6 +109,7 @@ func main() {
}
}
color.Unset()
fmt.Print("\n")
}
}