mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Fix formatting of lines with only spaces
This commit is contained in:
@@ -81,6 +81,10 @@ var blue_fmt = color.New(color.FgBlue).SprintFunc()
|
|||||||
var green_fmt = color.New(color.FgGreen).SprintFunc()
|
var green_fmt = color.New(color.FgGreen).SprintFunc()
|
||||||
|
|
||||||
func format_line_with_indent(output io.Writer, text string, indent string, screen_width int) {
|
func format_line_with_indent(output io.Writer, text string, indent string, screen_width int) {
|
||||||
|
if strings.TrimSpace(text) == "" {
|
||||||
|
fmt.Fprintln(output, indent)
|
||||||
|
return
|
||||||
|
}
|
||||||
x := len(indent)
|
x := len(indent)
|
||||||
fmt.Fprint(output, indent)
|
fmt.Fprint(output, indent)
|
||||||
in_escape := 0
|
in_escape := 0
|
||||||
|
|||||||
@@ -5,14 +5,20 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFormatLineWithIndent(t *testing.T) {
|
func TestFormatWithIndent(t *testing.T) {
|
||||||
var output strings.Builder
|
var output strings.Builder
|
||||||
|
indent := "__"
|
||||||
|
screen_width := 11
|
||||||
|
|
||||||
|
run := func(text string, expected ...string) {
|
||||||
output.Reset()
|
output.Reset()
|
||||||
indent := " "
|
q := indent + strings.Join(expected, "\n"+indent) + "\n"
|
||||||
format_line_with_indent(&output, "testing \x1b[31mstyled\x1b[m", indent, 11)
|
format_with_indent(&output, text, indent, screen_width)
|
||||||
expected := indent + "testing \n" + indent + "\x1b[31mstyled\x1b[m\n"
|
if output.String() != q {
|
||||||
if output.String() != expected {
|
t.Fatalf("expected != actual: %#v != %#v", q, output.String())
|
||||||
t.Fatalf("%#v != %#v", expected, output.String())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
run("testing \x1b[31mstyled\x1b[m", "testing ", "\x1b[31mstyled\x1b[m")
|
||||||
|
run("testing\n\ntwo", "testing", "", "two")
|
||||||
|
run("testing\n \ntwo", "testing", "", "two")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user