mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 05:54:59 +02:00
Use SIMD to replace C0 control codes in Go code
This commit is contained in:
@@ -3,9 +3,9 @@ package highlight
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/chroma/v2"
|
||||
"github.com/kovidgoyal/kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@@ -19,29 +19,6 @@ type StyleResolveData interface {
|
||||
TextForPath(string) (string, error)
|
||||
}
|
||||
|
||||
type SanitizeControlCodes struct {
|
||||
r *strings.Replacer
|
||||
}
|
||||
|
||||
func (s SanitizeControlCodes) Sanitize(x string) string { return s.r.Replace(x) }
|
||||
|
||||
func NewSanitizeControlCodes(replace_tab_by string) *SanitizeControlCodes {
|
||||
repls := make([]string, 0, 2*(0x1f+2+(0x9f-0x80+1)))
|
||||
for i := range 0x1f + 1 {
|
||||
var repl string
|
||||
switch i {
|
||||
case '\n', ' ':
|
||||
repl = string(rune(i))
|
||||
case '\t':
|
||||
repl = replace_tab_by
|
||||
default:
|
||||
repl = string(rune(0x2400 + i))
|
||||
}
|
||||
repls = append(repls, string(rune(i)), repl)
|
||||
}
|
||||
return &SanitizeControlCodes{r: strings.NewReplacer(repls...)}
|
||||
}
|
||||
|
||||
type Highlighter interface {
|
||||
HighlightFile(path string, srd StyleResolveData) (highlighted_string string, err error)
|
||||
Sanitize(string) string
|
||||
@@ -49,8 +26,7 @@ type Highlighter interface {
|
||||
|
||||
func NewHighlighter(sanitize func(string) string) Highlighter {
|
||||
if sanitize == nil {
|
||||
s := NewSanitizeControlCodes(" ")
|
||||
sanitize = s.Sanitize
|
||||
sanitize = func(text string) string { return utils.ReplaceControlCodes(text, " ", "\n") }
|
||||
}
|
||||
return &highlighter{sanitize: sanitize, tokens_map: make(map[string][]chroma.Token)}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user