Disable syntax highlighting
This commit is contained in:
parent
25dfc2efe2
commit
bbdccb0ff6
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@ -81,43 +80,43 @@ loop:
|
|||||||
t.selection = buffer.NewRegion(&t.Buffer)
|
t.selection = buffer.NewRegion(&t.Buffer)
|
||||||
|
|
||||||
// TODO: replace with automatic determination of language via filetype
|
// TODO: replace with automatic determination of language via filetype
|
||||||
lang := &buffer.Language{
|
//lang := &buffer.Language{
|
||||||
Name: "Go",
|
// Name: "Go",
|
||||||
Filetypes: []string{".go"},
|
// Filetypes: []string{".go"},
|
||||||
Rules: map[*buffer.RegexpRegion]buffer.Syntax{
|
// Rules: map[*buffer.RegexpRegion]buffer.Syntax{
|
||||||
{Start: regexp.MustCompile(`\/\/.*`)}: buffer.Comment,
|
// {Start: regexp.MustCompile(`\/\/.*`)}: buffer.Comment,
|
||||||
{Start: regexp.MustCompile(`".*?"`)}: buffer.String,
|
// {Start: regexp.MustCompile(`".*?"`)}: buffer.String,
|
||||||
{
|
// {
|
||||||
Start: regexp.MustCompile(`\b(var|const|if|else|range|for|switch|fallthrough|case|default|break|continue|go|func|return|defer|import|type|package)\b`),
|
// Start: regexp.MustCompile(`\b(var|const|if|else|range|for|switch|fallthrough|case|default|break|continue|go|func|return|defer|import|type|package)\b`),
|
||||||
}: buffer.Keyword,
|
// }: buffer.Keyword,
|
||||||
{
|
// {
|
||||||
Start: regexp.MustCompile(`\b(u?int(8|16|32|64)?|rune|byte|string|bool|struct)\b`),
|
// Start: regexp.MustCompile(`\b(u?int(8|16|32|64)?|rune|byte|string|bool|struct)\b`),
|
||||||
}: buffer.Type,
|
// }: buffer.Type,
|
||||||
{
|
// {
|
||||||
Start: regexp.MustCompile(`\b([1-9][0-9]*|0[0-7]*|0[Xx][0-9A-Fa-f]+|0[Bb][01]+)\b`),
|
// Start: regexp.MustCompile(`\b([1-9][0-9]*|0[0-7]*|0[Xx][0-9A-Fa-f]+|0[Bb][01]+)\b`),
|
||||||
}: buffer.Number,
|
// }: buffer.Number,
|
||||||
{
|
// {
|
||||||
Start: regexp.MustCompile(`\b(len|cap|panic|make|copy|append)\b`),
|
// Start: regexp.MustCompile(`\b(len|cap|panic|make|copy|append)\b`),
|
||||||
}: buffer.Builtin,
|
// }: buffer.Builtin,
|
||||||
{
|
// {
|
||||||
Start: regexp.MustCompile(`\b(nil|true|false)\b`),
|
// Start: regexp.MustCompile(`\b(nil|true|false)\b`),
|
||||||
}: buffer.Special,
|
// }: buffer.Special,
|
||||||
},
|
// },
|
||||||
}
|
//}
|
||||||
|
|
||||||
colorscheme := &buffer.Colorscheme{
|
//colorscheme := &buffer.Colorscheme{
|
||||||
buffer.Default: tcell.Style{}.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack),
|
// buffer.Default: tcell.Style{}.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack),
|
||||||
buffer.Column: tcell.Style{}.Foreground(tcell.ColorDarkGray).Background(tcell.ColorBlack),
|
// buffer.Column: tcell.Style{}.Foreground(tcell.ColorDarkGray).Background(tcell.ColorBlack),
|
||||||
buffer.Comment: tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
// buffer.Comment: tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
||||||
buffer.String: tcell.Style{}.Foreground(tcell.ColorOlive).Background(tcell.ColorBlack),
|
// buffer.String: tcell.Style{}.Foreground(tcell.ColorOlive).Background(tcell.ColorBlack),
|
||||||
buffer.Keyword: tcell.Style{}.Foreground(tcell.ColorNavy).Background(tcell.ColorBlack),
|
// buffer.Keyword: tcell.Style{}.Foreground(tcell.ColorNavy).Background(tcell.ColorBlack),
|
||||||
buffer.Type: tcell.Style{}.Foreground(tcell.ColorPurple).Background(tcell.ColorBlack),
|
// buffer.Type: tcell.Style{}.Foreground(tcell.ColorPurple).Background(tcell.ColorBlack),
|
||||||
buffer.Number: tcell.Style{}.Foreground(tcell.ColorFuchsia).Background(tcell.ColorBlack),
|
// buffer.Number: tcell.Style{}.Foreground(tcell.ColorFuchsia).Background(tcell.ColorBlack),
|
||||||
buffer.Builtin: tcell.Style{}.Foreground(tcell.ColorBlue).Background(tcell.ColorBlack),
|
// buffer.Builtin: tcell.Style{}.Foreground(tcell.ColorBlue).Background(tcell.ColorBlack),
|
||||||
buffer.Special: tcell.Style{}.Foreground(tcell.ColorFuchsia).Background(tcell.ColorBlack),
|
// buffer.Special: tcell.Style{}.Foreground(tcell.ColorFuchsia).Background(tcell.ColorBlack),
|
||||||
}
|
//}
|
||||||
|
|
||||||
t.Highlighter = buffer.NewHighlighter(t.Buffer, lang, colorscheme)
|
//t.Highlighter = buffer.NewHighlighter(t.Buffer, lang, colorscheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLineDelimiter returns "\r\n" for a CRLF buffer, or "\n" for an LF buffer.
|
// GetLineDelimiter returns "\r\n" for a CRLF buffer, or "\n" for an LF buffer.
|
||||||
@ -187,11 +186,13 @@ func (t *TextEdit) Delete(forwards bool) {
|
|||||||
t.ScrollToCursor()
|
t.ScrollToCursor()
|
||||||
t.updateCursorVisibility()
|
t.updateCursorVisibility()
|
||||||
|
|
||||||
|
if t.Highlighter != nil {
|
||||||
if deletedLine {
|
if deletedLine {
|
||||||
t.Highlighter.InvalidateLines(startingLine, t.Buffer.Lines()-1)
|
t.Highlighter.InvalidateLines(startingLine, t.Buffer.Lines()-1)
|
||||||
} else {
|
} else {
|
||||||
t.Highlighter.InvalidateLines(startingLine, startingLine)
|
t.Highlighter.InvalidateLines(startingLine, startingLine)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes `contents` at the cursor position. Line delimiters and tab character supported.
|
// Writes `contents` at the cursor position. Line delimiters and tab character supported.
|
||||||
@ -241,11 +242,13 @@ func (t *TextEdit) Insert(contents string) {
|
|||||||
t.ScrollToCursor()
|
t.ScrollToCursor()
|
||||||
t.updateCursorVisibility()
|
t.updateCursorVisibility()
|
||||||
|
|
||||||
|
if t.Highlighter != nil {
|
||||||
if lineInserted {
|
if lineInserted {
|
||||||
t.Highlighter.InvalidateLines(startingLine, t.Buffer.Lines()-1)
|
t.Highlighter.InvalidateLines(startingLine, t.Buffer.Lines()-1)
|
||||||
} else {
|
} else {
|
||||||
t.Highlighter.InvalidateLines(startingLine, startingLine)
|
t.Highlighter.InvalidateLines(startingLine, startingLine)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTabCountInLineAtCol returns tabs in the given line, before the column position,
|
// getTabCountInLineAtCol returns tabs in the given line, before the column position,
|
||||||
@ -334,9 +337,17 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
bufferLines := t.Buffer.Lines()
|
bufferLines := t.Buffer.Lines()
|
||||||
|
|
||||||
selectedStyle := t.theme.GetOrDefault("TextEditSelected")
|
selectedStyle := t.theme.GetOrDefault("TextEditSelected")
|
||||||
columnStyle := t.Highlighter.Colorscheme.GetStyle(buffer.Column)
|
|
||||||
|
var columnStyle, defaultStyle tcell.Style
|
||||||
|
if t.Highlighter != nil {
|
||||||
|
defaultStyle = t.Highlighter.Colorscheme.GetStyle(buffer.Default)
|
||||||
|
columnStyle = t.Highlighter.Colorscheme.GetStyle(buffer.Column)
|
||||||
|
|
||||||
t.Highlighter.UpdateInvalidatedLines(t.scrolly, t.scrolly+(t.height-1))
|
t.Highlighter.UpdateInvalidatedLines(t.scrolly, t.scrolly+(t.height-1))
|
||||||
|
} else {
|
||||||
|
defaultStyle = t.theme.GetOrDefault("TextEditDefault")
|
||||||
|
columnStyle = t.theme.GetOrDefault("TextEditColumn")
|
||||||
|
}
|
||||||
|
|
||||||
var tabBytes []byte
|
var tabBytes []byte
|
||||||
if t.UseHardTabs {
|
if t.UseHardTabs {
|
||||||
@ -344,7 +355,6 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
tabBytes = bytes.Repeat([]byte{' '}, t.TabSize)
|
tabBytes = bytes.Repeat([]byte{' '}, t.TabSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultStyle := t.Highlighter.Colorscheme.GetStyle(buffer.Default)
|
|
||||||
currentStyle := defaultStyle
|
currentStyle := defaultStyle
|
||||||
|
|
||||||
for lineY := t.y; lineY < t.y+t.height; lineY++ { // For each line we can draw...
|
for lineY := t.y; lineY < t.y+t.height; lineY++ { // For each line we can draw...
|
||||||
@ -362,7 +372,10 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
lineBytes = bytes.ReplaceAll(lineBytes, []byte{'\t'}, tabBytes)
|
lineBytes = bytes.ReplaceAll(lineBytes, []byte{'\t'}, tabBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
lineHighlightData := t.Highlighter.GetLineMatches(line)
|
var lineHighlightData []buffer.Match
|
||||||
|
if t.Highlighter != nil {
|
||||||
|
lineHighlightData = t.Highlighter.GetLineMatches(line)
|
||||||
|
}
|
||||||
var lineHighlightDataIdx int
|
var lineHighlightDataIdx int
|
||||||
|
|
||||||
var byteIdx int // Byte index of lineStr
|
var byteIdx int // Byte index of lineStr
|
||||||
|
@ -39,7 +39,9 @@ var DefaultTheme = Theme{
|
|||||||
"TabContainer": tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
"TabContainer": tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
||||||
"TabContainerFocused": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
"TabContainerFocused": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||||
"TextEdit": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
"TextEdit": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||||
|
"TextEditDefault": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
|
||||||
"TextEditSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
"TextEditSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||||
|
"TextEditColumn": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorGray),
|
||||||
"Window": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorDarkGray),
|
"Window": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorDarkGray),
|
||||||
"WindowHeader": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
"WindowHeader": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user