From bfdb7c80aa919f73b79f1b79b758265ee91c7116 Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Fri, 23 Aug 2024 08:01:42 +0800 Subject: [PATCH] fix: first line not wrapping correctly --- pkg/emu/flow_test.go | 23 +++++++++++++++++++++++ pkg/emu/wrap.go | 8 +------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pkg/emu/flow_test.go b/pkg/emu/flow_test.go index a67cb293..4c88c423 100644 --- a/pkg/emu/flow_test.go +++ b/pkg/emu/flow_test.go @@ -335,3 +335,26 @@ func TestGetLines(t *testing.T) { require.Equal(t, "foobar", lines[0].String()) require.Equal(t, "baz", lines[1].String()) } + +func TestBrokenLine(t *testing.T) { + term := New() + term.Write([]byte(LineFeedMode)) + + setup := []string{ + "> ", "command\n", + } + + bigWrite := "" + for row := 0; row < geom.DEFAULT_SIZE.R*2; row++ { + bigWrite += "foo\n" + } + setup = append(setup, bigWrite) + setup = append(setup, "> ") + + for _, item := range setup { + term.Write([]byte(item)) + } + + lines := term.GetLines(0, 0) + require.Equal(t, "> command", lines[0].String()) +} diff --git a/pkg/emu/wrap.go b/pkg/emu/wrap.go index d96d4226..45b8e671 100644 --- a/pkg/emu/wrap.go +++ b/pkg/emu/wrap.go @@ -109,14 +109,8 @@ func isWrappedLines(lines []Line) bool { } func appendWrapped(lines []Line, line Line) []Line { - // TODO(cfoust): 05/13/24 test this? - if len(lines) == 0 { - return append(lines, copyLine(line)) - } - cloned := getOccupiedLine(copyLine(line)) - - if !isWrappedLines(lines) { + if len(lines) == 0 || !isWrappedLines(lines) { return append(lines, cloned) }