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