diff --git a/pkg/emu/state.go b/pkg/emu/state.go index 10d3eb8f..c236d22a 100644 --- a/pkg/emu/state.go +++ b/pkg/emu/state.go @@ -276,6 +276,7 @@ func (t *State) reset() { // TODO: definitely can improve allocs func (t *State) resize(size geom.Vec2) { + oldCols := t.cols cols := size.C rows := size.R if cols == t.cols && rows == t.rows { @@ -378,13 +379,13 @@ func (t *State) resize(size geom.Vec2) { } copy(t.tabs, tabs) - if cols > t.cols { - i := t.cols - 1 + if cols > oldCols && oldCols > 0 { + i := oldCols - 1 for i > 0 && !tabs[i] { i-- } - for i += tabspaces; i < len(tabs); i += tabspaces { - tabs[i] = true + for i += tabspaces; i < len(t.tabs); i += tabspaces { + t.tabs[i] = true } } diff --git a/pkg/emu/vt_test.go b/pkg/emu/vt_test.go index 69dc2181..a88ef87b 100644 --- a/pkg/emu/vt_test.go +++ b/pkg/emu/vt_test.go @@ -108,3 +108,14 @@ func TestPrompt(t *testing.T) { require.True(t, value) require.True(t, ok) } + +func TestTabs(t *testing.T) { + term := New() + // This is the simplest example of a bug that I encountered with tabs. + term.Resize(geom.Vec2{C: 172, R: 3}) + term.Write([]byte(LineFeedMode)) + term.Write([]byte("LICENSE\t\tcmd\t\tdaemon.log\terr.log\t\tgo.sum\t\tmain\t\tscreenshot.gif\tstories.log\ttrace.prof\r\n")) + first := term.Screen()[0].String() + index := strings.Index(first, "trace.prof") + require.NotEqual(t, -1, index) +}