fix: avoid terminal probes before CLI output (#4994)

This commit is contained in:
守澄
2026-06-05 12:10:15 -07:00
committed by GitHub
parent 48f31cb60d
commit f405cc3f83
2 changed files with 36 additions and 8 deletions
+10 -8
View File
@@ -18,11 +18,17 @@ var (
helpStyle = blurredStyle
// cursorStyle = focusedStyle.
// cursorModeHelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("244"))
focusedSkipButton = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).Render("[ Run with defaults ]")
blurredSkipButton = fmt.Sprintf("[ %s ]", lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Render("Run with defaults"))
)
func skipButtonView(focused bool) string {
// Keep rendering lazy. Rendering lipgloss styles at package init can make
// terminal color detection write escape sequences before non-TUI commands run.
if focused {
return focusedStyle.Render("[ Run with defaults ]")
}
return fmt.Sprintf("[ %s ]", blurredStyle.Render("Run with defaults"))
}
// SelectNextMsg used for emitting events when the 'Next' button is selected.
type SelectNextMsg int
@@ -179,11 +185,7 @@ func (m Model) View() string {
}
if m.skipButton {
button := &blurredSkipButton
if m.focusIndex == -1 {
button = &focusedSkipButton
}
fmt.Fprintf(&b, "%s\n\n\n", *button)
fmt.Fprintf(&b, "%s\n\n\n", skipButtonView(m.focusIndex == -1))
}
for i := range m.inputs {
@@ -0,0 +1,26 @@
package textinputs
import (
"strings"
"testing"
)
func TestSkipButtonViewIsRenderedLazily(t *testing.T) {
m := New(nil).SetSkip(true)
view := m.View()
if !strings.Contains(view, "Run with defaults") {
t.Fatalf("expected skip button text in view, got %q", view)
}
}
func TestSkipButtonViewIsHiddenByDefault(t *testing.T) {
m := New(nil)
view := m.View()
if strings.Contains(view, "Run with defaults") {
t.Fatalf("did not expect skip button text in default view, got %q", view)
}
}