Skip to content

Commit

Permalink
feat: add WithWindowSize option to set the initial window size
Browse files Browse the repository at this point in the history
This adds a new option to set the initial window size of the terminal
window. This is useful in testing and required for teatest/v2 after the
changes in the renderer. The cell-based cursed renderer heavily relies
on the terminal size, and it's important to have a way to set the size
manually for tests to run in a non-interactive environment.
  • Loading branch information
aymanbagabas committed Feb 7, 2025
1 parent 076054d commit 1801ebd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 11 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,14 @@ func WithColorProfile(profile colorprofile.Profile) ProgramOption {
p.profile = profile
}
}

// WithWindowSize sets the initial size of the terminal window. This is useful
// when you need to set the initial size of the terminal window, for example
// during testing or when you want to run your program in a non-interactive
// environment.
func WithWindowSize(width, height int) ProgramOption {
return func(p *Program) {
p.width = width
p.height = height
}
}
7 changes: 3 additions & 4 deletions screen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ func TestClearMsg(t *testing.T) {
"TERM=xterm-256color", // always use xterm and 256 colors for tests
}),
// Use ANSI256 to increase test coverage.
WithColorProfile(colorprofile.ANSI256))

// Set the initial window size for the program.
p.width, p.height = 80, 24
WithColorProfile(colorprofile.ANSI256),
// Set the initial window size for the program.
WithWindowSize(80, 24))

go p.Send(append(test.cmds, Quit))

Expand Down

0 comments on commit 1801ebd

Please sign in to comment.