diff --git a/tools/cli/help.go b/tools/cli/help.go index 548944e3c..55b3fd6f6 100644 --- a/tools/cli/help.go +++ b/tools/cli/help.go @@ -37,6 +37,7 @@ func (self *Command) ShowVersion() { func format_with_indent(output io.Writer, text string, indent string, screen_width int) { indented := style.WrapText(text, indent, screen_width, "#placeholder_for_formatting#") io.WriteString(output, indented) + io.WriteString(output, "\n") } func (self *Command) FormatSubCommands(output io.Writer, formatter *markup.Context, screen_width int) { diff --git a/tools/cmd/diff/render.go b/tools/cmd/diff/render.go index 3c228126e..14f19c077 100644 --- a/tools/cmd/diff/render.go +++ b/tools/cmd/diff/render.go @@ -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 { - lines := style.WrapTextAsLines(text, "", width) - if len(lines) > 1 && lines[len(lines)-1] == "" { - lines = lines[:len(lines)-1] - } - return lines + return style.WrapTextAsLines(text, "", width) } func render_half_line(line_number int, line, ltype string, margin_size, available_cols int, center Center, ans []string) []string { diff --git a/tools/utils/style/indent-and-wrap.go b/tools/utils/style/indent-and-wrap.go index d748af970..ebeb7061e 100644 --- a/tools/utils/style/indent-and-wrap.go +++ b/tools/utils/style/indent-and-wrap.go @@ -481,7 +481,9 @@ func (self *wrapper) wrap_text(text string) []string { if last_line == self.current_line.reset() { last_line = "" } - self.append_line(last_line) + if last_line != "" { + self.append_line(last_line) + } return self.lines } diff --git a/tools/utils/style/indent-and-wrap_test.go b/tools/utils/style/indent-and-wrap_test.go index 933170558..be81c8112 100644 --- a/tools/utils/style/indent-and-wrap_test.go +++ b/tools/utils/style/indent-and-wrap_test.go @@ -12,7 +12,7 @@ func TestFormatWithIndent(t *testing.T) { screen_width := 11 tx := func(text string, expected ...string) { - q := indent + strings.Join(expected, "") + "\n" + q := indent + strings.Join(expected, "") actual := WrapText(text, indent, screen_width) if actual != q { t.Fatalf("%#v\nexpected: %#v\nactual: %#v", text, q, actual) @@ -35,4 +35,6 @@ func TestFormatWithIndent(t *testing.T) { screen_width = 3 tx("one", "one") tx("four", "fou\nr") + tx("nl\n\n", "nl\n\n") + tx("four\n\n", "fou\nr\n\n") }