Implement previews for plain text files

This commit is contained in:
Kovid Goyal
2025-07-20 19:24:17 +05:30
parent 28fce006d6
commit bd0f55531f
10 changed files with 185 additions and 25 deletions

View File

@@ -44,6 +44,7 @@ func NewSanitizeControlCodes(replace_tab_by string) *SanitizeControlCodes {
type Highlighter interface {
HighlightFile(path string, srd StyleResolveData) (highlighted_string string, err error)
Sanitize(string) string
}
func NewHighlighter(sanitize func(string) string) Highlighter {

View File

@@ -180,6 +180,8 @@ type highlighter struct {
sanitize func(string) string
}
func (h *highlighter) Sanitize(x string) string { return h.sanitize(x) }
func (h *highlighter) HighlightFile(path string, srd StyleResolveData) (highlighted_string string, err error) {
defer func() {
if r := recover(); r != nil {

View File

@@ -5,6 +5,7 @@ package wcswidth
import (
"errors"
"fmt"
"io"
"strconv"
"github.com/kovidgoyal/kitty/tools/utils"
@@ -50,6 +51,17 @@ func (self *truncate_iterator) handle_st_terminated_escape_code(body []byte) err
return nil
}
func KeepOnlyCSI(text string, output io.Writer) {
var w WCWidthIterator
w.parser.HandleCSI = func(data []byte) (err error) {
_, err = output.Write([]byte{'\x1b', '['})
if err == nil {
_, err = output.Write(data)
}
return
}
}
func create_truncate_iterator() *truncate_iterator {
var ans truncate_iterator
ans.w.parser.HandleRune = ans.handle_rune