mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-18 14:34:52 +02:00
Use SIMD to replace C0 control codes in Go code
This commit is contained in:
@@ -9,10 +9,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/kovidgoyal/kitty/tools/highlight"
|
||||
"github.com/kovidgoyal/kitty/tools/utils"
|
||||
)
|
||||
|
||||
@@ -125,10 +123,7 @@ func text_to_lines(text string) []string {
|
||||
return lines
|
||||
}
|
||||
|
||||
var sanitize = sync.OnceValue(func() func(string) string {
|
||||
s := highlight.NewSanitizeControlCodes(conf.Replace_tab_by)
|
||||
return s.Sanitize
|
||||
})
|
||||
func sanitize(text string) string { return utils.ReplaceControlCodes(text, conf.Replace_tab_by, "\n") }
|
||||
|
||||
func lines_for_path(path string) ([]string, error) {
|
||||
return lines_cache.GetOrCreate(path, func(path string) ([]string, error) {
|
||||
@@ -136,7 +131,7 @@ func lines_for_path(path string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return text_to_lines(sanitize()(ans)), nil
|
||||
return text_to_lines(sanitize(ans)), nil
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ func (s prefer_light_colors) SyntaxAliases() map[string]string { return c
|
||||
func (s prefer_light_colors) TextForPath(path string) (string, error) { return data_for_path(path) }
|
||||
|
||||
var highlighter = sync.OnceValue(func() highlight.Highlighter {
|
||||
return highlight.NewHighlighter(sanitize())
|
||||
return highlight.NewHighlighter(sanitize)
|
||||
})
|
||||
|
||||
func highlight_all(paths []string, light bool) {
|
||||
|
||||
@@ -284,10 +284,10 @@ func title_lines(left_path, right_path string, columns, margin_size int, ans []*
|
||||
}
|
||||
sl := ScreenLine{}
|
||||
if right_name != "" && right_name != left_name {
|
||||
sl.left.marked_up_text = format_as_sgr.title + fit_in(sanitize()(left_name), available_cols)
|
||||
sl.right.marked_up_text = format_as_sgr.title + fit_in(sanitize()(right_name), available_cols)
|
||||
sl.left.marked_up_text = format_as_sgr.title + fit_in(sanitize(left_name), available_cols)
|
||||
sl.right.marked_up_text = format_as_sgr.title + fit_in(sanitize(right_name), available_cols)
|
||||
} else {
|
||||
sl.left.marked_up_text = format_as_sgr.title + fit_in(sanitize()(left_name), columns-margin_size)
|
||||
sl.left.marked_up_text = format_as_sgr.title + fit_in(sanitize(left_name), columns-margin_size)
|
||||
ll.is_full_width = true
|
||||
}
|
||||
l2 := ll
|
||||
@@ -755,7 +755,7 @@ func rename_lines(path, other_path string, columns, margin_size int, ans []*Logi
|
||||
ll := LogicalLine{
|
||||
left_reference: Reference{path: path}, right_reference: Reference{path: other_path},
|
||||
line_type: CHANGE_LINE, is_change_start: true, is_full_width: true}
|
||||
for _, line := range splitlines(fmt.Sprintf(`The file %s was renamed to %s`, sanitize()(path_name_map[path]), sanitize()(path_name_map[other_path])), columns-margin_size) {
|
||||
for _, line := range splitlines(fmt.Sprintf(`The file %s was renamed to %s`, sanitize(path_name_map[path]), sanitize(path_name_map[other_path])), columns-margin_size) {
|
||||
sl := ScreenLine{}
|
||||
sl.right.marked_up_text = line
|
||||
ll.screen_lines = append(ll.screen_lines, &sl)
|
||||
|
||||
@@ -446,7 +446,7 @@ func (self *Handler) draw_status_line() {
|
||||
if self.inputting_command {
|
||||
self.rl.RedrawNonAtomic()
|
||||
} else if self.statusline_message != "" {
|
||||
self.lp.QueueWriteString(message_format(wcswidth.TruncateToVisualLength(sanitize()(self.statusline_message), self.screen_size.columns)))
|
||||
self.lp.QueueWriteString(message_format(wcswidth.TruncateToVisualLength(sanitize(self.statusline_message), self.screen_size.columns)))
|
||||
} else {
|
||||
num := self.logical_lines.NumScreenLinesTo(self.scroll_pos)
|
||||
den := self.logical_lines.NumScreenLinesTo(self.max_scroll_pos)
|
||||
|
||||
Reference in New Issue
Block a user