You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Terminal colors encodings visible in app logs #1366
Hi I'd like to take a look at this. It looks like subprocess output containing ANSI escape sequences is being passed through to the web app logs without stripping. I'm planning to add an ANSI-sanitizing utility and apply it at the Terraform/Ansible output capture points. Will submit a PR once I have a working fix.
This is a common issue when terminal output with ANSI color codes is displayed in a web interface. The color codes (like \x1b[31m for red) are not being stripped before rendering.
Solutions:
Strip ANSI codes before logging:
importredefstrip_ansi_codes(text: str) ->str:
"""Remove ANSI escape codes from text."""ansi_escape=re.compile(r'\x1b\[[0-9;]*m')
returnansi_escape.sub('', text)
# Use when logginglogger.info(strip_ansi_codes(output))
importsysimportosdefshould_use_colors():
"""Check if we should use colors (TTY, not piped, etc.)."""return (
hasattr(sys.stdout, 'isatty') andsys.stdout.isatty() andos.environ.get('TERM') !='dumb'
)
# Disable colors when not in a terminaluse_colors=should_use_colors()
For subprocess output:
importsubprocessresult=subprocess.run(
command,
capture_output=True,
text=True,
env={**os.environ, 'TERM': 'dumb'} # Force no colors
)
The cleanest solution is usually #1 (strip at log time) or #3 (prevent colors in non-TTY environments).
Happy to help review a PR implementing any of these approaches!
Activity
cray44 commentedon May 8, 2026
Hi I'd like to take a look at this. It looks like subprocess output containing ANSI escape sequences is being passed through to the web app logs without stripping. I'm planning to add an ANSI-sanitizing utility and apply it at the Terraform/Ansible output capture points. Will submit a PR once I have a working fix.
janderik commentedon Jul 22, 2026
This is a common issue when terminal output with ANSI color codes is displayed in a web interface. The color codes (like
\x1b[31mfor red) are not being stripped before rendering.Solutions:
The cleanest solution is usually #1 (strip at log time) or #3 (prevent colors in non-TTY environments).
Happy to help review a PR implementing any of these approaches!