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

@@ -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