Do not add a trailing newline when wrapping

This commit is contained in:
Kovid Goyal 2023-03-20 21:18:53 +05:30
parent e42b4fd9a6
commit 924cd4cadd
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 8 additions and 7 deletions

View File

@ -37,6 +37,7 @@ func (self *Command) ShowVersion() {
func format_with_indent(output io.Writer, text string, indent string, screen_width int) { func format_with_indent(output io.Writer, text string, indent string, screen_width int) {
indented := style.WrapText(text, indent, screen_width, "#placeholder_for_formatting#") indented := style.WrapText(text, indent, screen_width, "#placeholder_for_formatting#")
io.WriteString(output, indented) io.WriteString(output, indented)
io.WriteString(output, "\n")
} }
func (self *Command) FormatSubCommands(output io.Writer, formatter *markup.Context, screen_width int) { func (self *Command) FormatSubCommands(output io.Writer, formatter *markup.Context, screen_width int) {

View File

@ -235,11 +235,7 @@ func lines_for_context_chunk(data *DiffData, hunk_num int, chunk *Chunk, chunk_n
} }
func splitlines(text string, width int) []string { func splitlines(text string, width int) []string {
lines := style.WrapTextAsLines(text, "", width) return style.WrapTextAsLines(text, "", width)
if len(lines) > 1 && lines[len(lines)-1] == "" {
lines = lines[:len(lines)-1]
}
return lines
} }
func render_half_line(line_number int, line, ltype string, margin_size, available_cols int, center Center, ans []string) []string { func render_half_line(line_number int, line, ltype string, margin_size, available_cols int, center Center, ans []string) []string {

View File

@ -481,7 +481,9 @@ func (self *wrapper) wrap_text(text string) []string {
if last_line == self.current_line.reset() { if last_line == self.current_line.reset() {
last_line = "" last_line = ""
} }
if last_line != "" {
self.append_line(last_line) self.append_line(last_line)
}
return self.lines return self.lines
} }

View File

@ -12,7 +12,7 @@ func TestFormatWithIndent(t *testing.T) {
screen_width := 11 screen_width := 11
tx := func(text string, expected ...string) { tx := func(text string, expected ...string) {
q := indent + strings.Join(expected, "") + "\n" q := indent + strings.Join(expected, "")
actual := WrapText(text, indent, screen_width) actual := WrapText(text, indent, screen_width)
if actual != q { if actual != q {
t.Fatalf("%#v\nexpected: %#v\nactual: %#v", text, q, actual) t.Fatalf("%#v\nexpected: %#v\nactual: %#v", text, q, actual)
@ -35,4 +35,6 @@ func TestFormatWithIndent(t *testing.T) {
screen_width = 3 screen_width = 3
tx("one", "one") tx("one", "one")
tx("four", "fou\nr") tx("four", "fou\nr")
tx("nl\n\n", "nl\n\n")
tx("four\n\n", "fou\nr\n\n")
} }