Skip to content

fix: strip all ANSI escape sequences in terminal command output#838

Open
OmarAlaaeldein wants to merge 1 commit into
CodebuffAI:mainfrom
OmarAlaaeldein:fix/sudo-ansi-escape-tui-corruption
Open

fix: strip all ANSI escape sequences in terminal command output#838
OmarAlaaeldein wants to merge 1 commit into
CodebuffAI:mainfrom
OmarAlaaeldein:fix/sudo-ansi-escape-tui-corruption

Conversation

@OmarAlaaeldein

Copy link
Copy Markdown

This PR fixes TUI display and scroll corruption when running sudo or interactive commands.

  • Switch from stripColors to stripAnsi in run-terminal-command.ts to strip all VT/ANSI control codes (e.g. cursor movement, alternate screen).
  • Strip bare \r (carriage return) characters.
  • Set SUDO_PROMPT to a plain text string to prevent sudo from emitting decorated prompts.
  • Default TERM=dumb for child processes to suppress color/cursor escape sequences.

When sudo (or other interactive programs) run via run_terminal_command,
they can emit cursor-movement, scroll-region, alternate-screen and other
VT/ANSI control sequences that bleed into the TUI and corrupt the display
(garbage characters, broken scrolling).

Changes:
- Switch stripColors -> stripAnsi so ALL escape sequences are removed
  from captured stdout/stderr, not just SGR color codes (\x1B[...m).
- Strip bare \r characters that sudo uses to erase its password-prompt
  line after credentials are accepted.
- Set SUDO_PROMPT to a plain ASCII string so sudo never emits decorated
  (colored/formatted) prompts to /dev/tty.
- Default TERM=dumb (when not overridden by the caller) so child
  programs like git, less, and man suppress their own color/cursor output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant