fix: avoid terminal probes before CLI output#4994
Open
Hackerchen716 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Fixes #4654.
When TruffleHog runs in a TTY-like environment with machine-readable output, terminal probe escape sequences can be written before the first JSON log line. That makes the output invalid JSON for tools such as
jq.Problem
pkg/tui/components/textinputsrendered the skip button at package initialization time:focusedSkipButton = ...Render(...)blurredSkipButton = ...Render(...)Because
main.goimports the TUI package, this render-time side effect can happen even for non-TUI CLI commands. Rendering a lipgloss style may trigger terminal color/profile detection, which can write terminal probe sequences to stdout before command output starts.Solution
Render the skip button lazily from
Model.View()instead of pre-rendering it in package-level variables.This keeps the visible TUI behavior the same while avoiding terminal rendering side effects during package initialization.
Validation
Ran:
Also ran a focused pseudo-terminal check with a small local program that imports
pkg/tui/components/textinputsand prints JSON. The captured stdout started directly with:{"ok":true}The first 80 bytes contained no ESC byte.
Risk
Low. The change only moves skip button rendering from package initialization to view rendering. It does not change TUI state, key handling, or CLI output formatting directly.
Breaking Changes
None.
Reviewer Notes
The important part to review is that no lipgloss
Render()call remains in package-level initialization forpkg/tui/components/textinputs.Note
Low Risk
UI-only timing change for one button string; no auth, data, or CLI formatting logic changes beyond avoiding init-time terminal side effects.
Overview
Lazy-renders the TUI “Run with defaults” skip control so importing
pkg/tui/components/textinputsno longer runs lipglossRender()at package init. Pre-renderedfocusedSkipButton/blurredSkipButtonglobals are removed in favor ofskipButtonView(), called fromModel.View()when the skip option is enabled.This targets machine-readable CLI output (e.g. JSON for
jq) that was getting terminal probe escape sequences on stdout before the first log line when the TUI package was linked but the interactive UI was not shown.Tests assert the skip label appears when
SetSkip(true)and stays out of the default view.Reviewed by Cursor Bugbot for commit 540eb1e. Bugbot is set up for automated code reviews on this repo. Configure here.