mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-03 23:57:13 -04:00
Revise example.
This commit is contained in:
@@ -87,49 +87,68 @@ func helloWorld() {
|
|||||||
// Now we will print the string
|
// Now we will print the string
|
||||||
lines := strings.Split(inputString, "\n")
|
lines := strings.Split(inputString, "\n")
|
||||||
for lineN, l := range lines {
|
for lineN, l := range lines {
|
||||||
for colN, c := range l {
|
colN := 0
|
||||||
// Check if the group changed at the current position
|
for _, c := range l {
|
||||||
if group, ok := matches[lineN][colN]; ok {
|
if group, ok := matches[lineN][colN]; ok {
|
||||||
switch group {
|
switch group {
|
||||||
case highlight.Groups["statement"]:
|
case highlight.Groups["statement"]:
|
||||||
color.Set(color.FgGreen)
|
fallthrough
|
||||||
// There are more possible groups available than just these ones
|
case highlight.Groups["green"]:
|
||||||
case highlight.Groups["statement"]:
|
color.Set(color.FgGreen)
|
||||||
color.Set(color.FgGreen)
|
|
||||||
case highlight.Groups["identifier"]:
|
case highlight.Groups["identifier"]:
|
||||||
color.Set(color.FgBlue)
|
fallthrough
|
||||||
case highlight.Groups["preproc"]:
|
case highlight.Groups["blue"]:
|
||||||
color.Set(color.FgHiRed)
|
color.Set(color.FgHiBlue)
|
||||||
case highlight.Groups["special"]:
|
|
||||||
color.Set(color.FgRed)
|
case highlight.Groups["preproc"]:
|
||||||
case highlight.Groups["constant.string"]:
|
//fallthrough
|
||||||
color.Set(color.FgCyan)
|
//case highlight.Groups["high.red"]:
|
||||||
case highlight.Groups["constant"]:
|
color.Set(color.FgHiRed)
|
||||||
color.Set(color.FgCyan)
|
|
||||||
case highlight.Groups["constant.specialChar"]:
|
case highlight.Groups["special"]:
|
||||||
color.Set(color.FgHiMagenta)
|
fallthrough
|
||||||
case highlight.Groups["type"]:
|
case highlight.Groups["red"]:
|
||||||
color.Set(color.FgYellow)
|
color.Set(color.FgRed)
|
||||||
case highlight.Groups["constant.number"]:
|
|
||||||
color.Set(color.FgCyan)
|
case highlight.Groups["constant.string"]:
|
||||||
case highlight.Groups["comment"]:
|
fallthrough
|
||||||
color.Set(color.FgHiGreen)
|
case highlight.Groups["constant"]:
|
||||||
default:
|
fallthrough
|
||||||
|
case highlight.Groups["constant.number"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["cyan"]:
|
||||||
|
color.Set(color.FgCyan)
|
||||||
|
|
||||||
|
case highlight.Groups["constant.specialChar"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["magenta"]:
|
||||||
|
color.Set(color.FgHiMagenta)
|
||||||
|
|
||||||
|
case highlight.Groups["type"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["yellow"]:
|
||||||
|
color.Set(color.FgYellow)
|
||||||
|
|
||||||
|
case highlight.Groups["comment"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["high.green"]:
|
||||||
|
color.Set(color.FgHiGreen)
|
||||||
|
default:
|
||||||
|
color.Unset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Print(string(c))
|
||||||
|
colN++
|
||||||
|
}
|
||||||
|
if group, ok := matches[lineN][colN]; ok {
|
||||||
|
if group == highlight.Groups["default"] || group == highlight.Groups[""] {
|
||||||
color.Unset()
|
color.Unset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Print the character
|
|
||||||
fmt.Print(string(c))
|
|
||||||
}
|
|
||||||
// This is at a newline, but highlighting might have been turned off at the very end of the line so we should check that.
|
|
||||||
if group, ok := matches[lineN][len(l)]; ok {
|
|
||||||
if group == highlight.Groups["default"] || group == highlight.Groups[""] {
|
|
||||||
color.Unset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
color.Unset()
|
color.Unset()
|
||||||
fmt.Print("\n")
|
fmt.Print("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
+40
-17
@@ -22,12 +22,11 @@ func main() {
|
|||||||
|
|
||||||
var syn_dir string
|
var syn_dir string
|
||||||
if gopath == "" {
|
if gopath == "" {
|
||||||
syn_dir = "/etc/highlight"
|
syn_dir = os.Getenv("HOME") + "/.config/zaje/syntax_files"
|
||||||
} else {
|
} else {
|
||||||
syn_dir = gopath + "/src/github.com/jessp01/gohighlight/syntax_files"
|
syn_dir = gopath + "/src/github.com/jessp01/gohighlight/syntax_files"
|
||||||
}
|
}
|
||||||
|
|
||||||
syn_dir = os.Getenv("SYNDIR")
|
|
||||||
var defs []*highlight.Def
|
var defs []*highlight.Def
|
||||||
err := highlight.ParseSyntaxFiles(syn_dir, &defs)
|
err := highlight.ParseSyntaxFiles(syn_dir, &defs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,28 +52,51 @@ func main() {
|
|||||||
colN := 0
|
colN := 0
|
||||||
for _, c := range l {
|
for _, c := range l {
|
||||||
if group, ok := matches[lineN][colN]; ok {
|
if group, ok := matches[lineN][colN]; ok {
|
||||||
// There are more possible groups available than just these ones
|
switch group {
|
||||||
if group == highlight.Groups["statement"] {
|
case highlight.Groups["statement"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["green"]:
|
||||||
color.Set(color.FgGreen)
|
color.Set(color.FgGreen)
|
||||||
} else if group == highlight.Groups["identifier"] {
|
|
||||||
color.Set(color.FgBlue)
|
case highlight.Groups["identifier"]:
|
||||||
} else if group == highlight.Groups["preproc"] {
|
fallthrough
|
||||||
|
case highlight.Groups["blue"]:
|
||||||
|
color.Set(color.FgHiBlue)
|
||||||
|
|
||||||
|
case highlight.Groups["preproc"]:
|
||||||
|
//fallthrough
|
||||||
|
//case highlight.Groups["high.red"]:
|
||||||
color.Set(color.FgHiRed)
|
color.Set(color.FgHiRed)
|
||||||
} else if group == highlight.Groups["special"] {
|
|
||||||
|
case highlight.Groups["special"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["red"]:
|
||||||
color.Set(color.FgRed)
|
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)
|
color.Set(color.FgCyan)
|
||||||
} else if group == highlight.Groups["constant"] {
|
|
||||||
color.Set(color.FgCyan)
|
case highlight.Groups["constant.specialChar"]:
|
||||||
} else if group == highlight.Groups["constant.specialChar"] {
|
fallthrough
|
||||||
|
case highlight.Groups["magenta"]:
|
||||||
color.Set(color.FgHiMagenta)
|
color.Set(color.FgHiMagenta)
|
||||||
} else if group == highlight.Groups["type"] {
|
|
||||||
|
case highlight.Groups["type"]:
|
||||||
|
fallthrough
|
||||||
|
case highlight.Groups["yellow"]:
|
||||||
color.Set(color.FgYellow)
|
color.Set(color.FgYellow)
|
||||||
} else if group == highlight.Groups["constant.number"] {
|
|
||||||
color.Set(color.FgCyan)
|
case highlight.Groups["comment"]:
|
||||||
} else if group == highlight.Groups["comment"] {
|
fallthrough
|
||||||
|
case highlight.Groups["high.green"]:
|
||||||
color.Set(color.FgHiGreen)
|
color.Set(color.FgHiGreen)
|
||||||
} else {
|
default:
|
||||||
color.Unset()
|
color.Unset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,6 +109,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color.Unset()
|
||||||
fmt.Print("\n")
|
fmt.Print("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user