more tests for indent and wrap

This commit is contained in:
Kovid Goyal 2022-09-03 14:40:49 +05:30
parent af7f4e97cf
commit 3d79eb5730
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 16 additions and 8 deletions

View File

@ -232,7 +232,9 @@ func prettify(text string) string {
}
func format_with_indent(output io.Writer, text string, indent string, screen_width int) {
io.WriteString(output, style.WrapText(prettify(text), indent, screen_width, "#placeholder_for_formatting#"))
text = prettify(text)
indented := style.WrapText(text, indent, screen_width, "#placeholder_for_formatting#")
io.WriteString(output, indented)
}
func full_command_name(cmd *cobra.Command) string {

View File

@ -8,7 +8,6 @@ import (
"strings"
"unicode"
"kitty/tools/utils"
"kitty/tools/wcswidth"
)
@ -302,8 +301,7 @@ func (self *line_builder) add_escape_code2(prefix string, body []byte, suffix st
}
type escape_code_ struct {
prefix, suffix string
body []byte
prefix, body, suffix string
}
type word_builder struct {
@ -334,7 +332,7 @@ func (self *word_builder) width() int {
}
func (self *word_builder) add_escape_code(prefix string, body []byte, suffix string) {
e := escape_code_{prefix: prefix, body: body, suffix: suffix}
e := escape_code_{prefix: prefix, body: string(body), suffix: suffix}
self.escape_codes = append(self.escape_codes, e)
self.buf.WriteString(prefix)
self.buf.Write(body)
@ -419,9 +417,9 @@ func (self *wrapper) print_word() {
}
for _, e := range self.current_word.escape_codes {
if e.suffix != "" {
self.hyperlink.apply_osc(utils.UnsafeBytesToString(e.body))
self.hyperlink.apply_osc(e.body)
} else {
self.sgr.apply_csi(utils.UnsafeBytesToString(e.body))
self.sgr.apply_csi(e.body)
}
}
self.current_line.add_word(self.current_word.reset(), w)

View File

@ -18,10 +18,18 @@ func TestFormatWithIndent(t *testing.T) {
t.Fatalf("%#v\nexpected: %#v\nactual: %#v", text, q, actual)
}
}
tx("testing\n\ntwo", "testing\n\n__two")
tx("testing\n \ntwo", "testing\n\n__two")
a := strings.Repeat("a", screen_width-len(indent)-1)
tx(a+" b", a+"\n__b")
tx("123456 \x1b[31m789a", "123456\n__\x1b[31m789a")
tx("12 \x1b[31m789 abcd", "12 \x1b[31m789\n\x1b[39m__\x1b[31mabcd")
tx("\x1b]8;;x\x1b\\text\x1b]8;;\x1b\\ two", "\x1b]8;;x\x1b\\text\x1b]8;;\x1b\\ two")
tx("bb \x1b]8;;http://xyz.com\x1b\\text\x1b]8;;\x1b\\ two", "bb \x1b]8;;http://xyz.com\x1b\\text\x1b]8;;\x1b\\\n__two")
tx("\x1b[31maaaaaa \x1b[39mbbbbbb", "\x1b[31maaaaaa\n\x1b[39m__\x1b[31m\x1b[39mbbbbbb")
tx(
"\x1b[31;4:3m\x1b]8;;XXX\x1b\\combined using\x1b]8;;\x1b\\ operators",
"\x1b[31;4:3m\x1b]8;;XXX\x1b\\combined\n\x1b[4:0;39m\x1b]8;;\x1b\\__\x1b[4:3;31m\x1b]8;;XXX\x1b\\using\x1b]8;;\x1b\\\n\x1b[4:0;39m__\x1b[4:3;31moperators")
}