Highlight single-line comments (up to step 172)
This commit is contained in:
parent
ee99e553f0
commit
ca2fcdbede
@ -122,18 +122,32 @@ func (r *Row) updateSyntax() {
|
||||
return
|
||||
}
|
||||
|
||||
var scsIndex int = -1
|
||||
scs := s.LineCommentStart
|
||||
if len(scs) > 0 {
|
||||
scsIndex = strings.Index(string(r.render), scs)
|
||||
}
|
||||
|
||||
prevSep := true
|
||||
inString := '0'
|
||||
for i < r.RenderSize() {
|
||||
ch := r.render[i]
|
||||
prevHl := highlight.Normal
|
||||
|
||||
if i > 0 {
|
||||
prevHl = r.Hl[i-1]
|
||||
}
|
||||
|
||||
ip1 := i + 1
|
||||
|
||||
// Single line comments
|
||||
if inString == '0' && scsIndex == i {
|
||||
for j := scsIndex; j < r.RenderSize(); j++ {
|
||||
r.Hl[j] = highlight.Comment
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// String literals
|
||||
if s.Flags&highlight.HighlightStrings == highlight.HighlightStrings {
|
||||
// At the start of a string literal
|
||||
if inString == '0' && (ch == '"' || ch == '\'') {
|
||||
@ -166,6 +180,7 @@ func (r *Row) updateSyntax() {
|
||||
}
|
||||
}
|
||||
|
||||
// Numeric literals
|
||||
if s.Flags&highlight.HighlightNumbers == highlight.HighlightNumbers {
|
||||
if (unicode.IsDigit(ch) && (prevSep || prevHl == highlight.Number)) ||
|
||||
(ch == '.' && prevHl == highlight.Number) {
|
||||
|
@ -5,6 +5,7 @@ package highlight
|
||||
// ----------------------------------------------------------------------------
|
||||
const (
|
||||
Normal = iota
|
||||
Comment
|
||||
String
|
||||
Number
|
||||
Match
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
var syntaxColorMap = map[int]string{
|
||||
Comment: terminal.FGCyan,
|
||||
String: terminal.FGMagenta,
|
||||
Number: terminal.FGRed,
|
||||
Match: terminal.FGBlue,
|
||||
@ -34,6 +35,7 @@ func SyntaxToColor(hl int) string {
|
||||
type Syntax struct {
|
||||
FileType string
|
||||
FileMatch []string
|
||||
LineCommentStart string
|
||||
Flags int
|
||||
}
|
||||
|
||||
@ -41,14 +43,17 @@ type Syntax struct {
|
||||
var HLDB = []*Syntax{{
|
||||
"c",
|
||||
[]string{".c", ".h", ".cpp"},
|
||||
"//",
|
||||
HighlightNumbers | HighlightStrings,
|
||||
}, {
|
||||
"go",
|
||||
[]string{".go", "go.mod"},
|
||||
"//",
|
||||
HighlightNumbers | HighlightStrings,
|
||||
}, {
|
||||
"makefile",
|
||||
[]string{"Makefile", "makefile"},
|
||||
[]string{"Makefile", "makefile", "justfile"},
|
||||
"#",
|
||||
0,
|
||||
}}
|
||||
|
||||
@ -57,8 +62,11 @@ func GetSyntaxByFilename(filename string) *Syntax {
|
||||
return nil
|
||||
}
|
||||
|
||||
var ext string = ""
|
||||
extInd := strings.LastIndex(filename, ".")
|
||||
ext := filename[extInd:len(filename)]
|
||||
if extInd > -1 {
|
||||
ext = filename[extInd:len(filename)]
|
||||
}
|
||||
|
||||
for i := 0; i < len(HLDB); i++ {
|
||||
s := HLDB[i]
|
||||
|
Loading…
Reference in New Issue
Block a user