Skip to content

Commit

Permalink
fix: issue with broken tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Jun 26, 2024
1 parent d8f1ea2 commit bca68be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/emu/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/emu/vt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit bca68be

Please sign in to comment.