Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix: avoid terminal probes before CLI output (#4994)
守澄f405cc3f835e
diff --git a/pkg/tui/components/textinputs/textinputs.go b/pkg/tui/components/textinputs/textinputs.goindex 5f5a41804..e90e2aa2d 100644--- a/pkg/tui/components/textinputs/textinputs.go+++ b/pkg/tui/components/textinputs/textinputs.go@@ -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 {diff --git a/pkg/tui/components/textinputs/textinputs_test.go b/pkg/tui/components/textinputs/textinputs_test.gonew file mode 100644index 000000000..213e9efd7--- /dev/null+++ b/pkg/tui/components/textinputs/textinputs_test.go@@ -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)+ }+}