Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,17 @@ const (

// String return a human-readable value for the given [ProgressBarState].
func (s ProgressBarState) String() string {
return [...]string{
names := [...]string{
"None",
"Default",
"Error",
"Indeterminate",
"Warning",
}[s]
}
if s < 0 || int(s) >= len(names) {
return fmt.Sprintf("ProgressBarState(%d)", int(s))
}
return names[s]
}

// ProgressBar represents the terminal progress bar.
Expand Down
19 changes: 19 additions & 0 deletions tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,22 @@ func BenchmarkTeaRun(b *testing.B) {
_ = r.CloseWithError(io.EOF)
}
}

func TestProgressBarStateString(t *testing.T) {
for _, tc := range []struct {
state ProgressBarState
want string
}{
{ProgressBarNone, "None"},
{ProgressBarDefault, "Default"},
{ProgressBarError, "Error"},
{ProgressBarIndeterminate, "Indeterminate"},
{ProgressBarWarning, "Warning"},
{ProgressBarState(5), "ProgressBarState(5)"},
{ProgressBarState(-1), "ProgressBarState(-1)"},
} {
if got := tc.state.String(); got != tc.want {
t.Errorf("ProgressBarState(%d).String() = %q, want %q", int(tc.state), got, tc.want)
}
}
}