mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-02 07:07:15 -04:00
following gofmt -s
This commit is contained in:
+6
-6
@@ -4,9 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jessp01/highlight"
|
"github.com/jessp01/highlight"
|
||||||
@@ -22,16 +22,16 @@ func main() {
|
|||||||
|
|
||||||
var syn_dir string
|
var syn_dir string
|
||||||
if gopath == "" {
|
if gopath == "" {
|
||||||
syn_dir = "/etc/highlight"
|
syn_dir = "/etc/highlight"
|
||||||
}else{
|
} else {
|
||||||
syn_dir = gopath + "/src/github.com/jessp01/highlight/syntax_files"
|
syn_dir = gopath + "/src/github.com/jessp01/highlight/syntax_files"
|
||||||
}
|
}
|
||||||
|
|
||||||
syn_dir = os.Getenv("SYNDIR")
|
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 {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
highlight.ResolveIncludes(defs)
|
highlight.ResolveIncludes(defs)
|
||||||
|
|||||||
+3
-3
@@ -9,9 +9,9 @@ func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
if len(d.ftdetect) > 1 {
|
if len(d.ftdetect) > 1 {
|
||||||
if d.ftdetect[1].MatchString(string(firstLine)) {
|
if d.ftdetect[1].MatchString(string(firstLine)) {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-21
@@ -1,11 +1,11 @@
|
|||||||
package highlight
|
package highlight
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
"path/filepath"
|
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunePos returns the rune index of a given byte index
|
// RunePos returns the rune index of a given byte index
|
||||||
@@ -62,27 +62,27 @@ func NewHighlighter(def *Def) *Highlighter {
|
|||||||
// color's group (represented as one byte)
|
// color's group (represented as one byte)
|
||||||
type LineMatch map[int]Group
|
type LineMatch map[int]Group
|
||||||
|
|
||||||
func ParseSyntaxFiles (dir string, defs *[]*Def) error{
|
func ParseSyntaxFiles(dir string, defs *[]*Def) error {
|
||||||
pattern := "*.yaml"
|
pattern := "*.yaml"
|
||||||
files, err := filepath.Glob(dir + "/" + pattern)
|
files, err := filepath.Glob(dir + "/" + pattern)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, file_path := range(files){
|
|
||||||
file, err := ioutil.ReadFile(file_path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := ParseDef(file)
|
for _, file_path := range files {
|
||||||
if err != nil {
|
file, err := ioutil.ReadFile(file_path)
|
||||||
return err
|
if err != nil {
|
||||||
continue
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d, err := ParseDef(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
*defs = append(*defs, d)
|
||||||
}
|
}
|
||||||
*defs = append(*defs, d)
|
return nil
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
|
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
|
||||||
@@ -225,9 +225,8 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE
|
|||||||
|
|
||||||
func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []rune, statesOnly bool) LineMatch {
|
func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []rune, statesOnly bool) LineMatch {
|
||||||
if h.Def.rules == nil {
|
if h.Def.rules == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if len(line) == 0 {
|
if len(line) == 0 {
|
||||||
if canMatchEnd {
|
if canMatchEnd {
|
||||||
|
|||||||
Reference in New Issue
Block a user