Skip to content

Commit a12f765

Browse files
fix(keepopen): honour NO_COLOR and auto-strip ANSI for non-TTY stdout (#176)
## Summary `keepopen.sh` always emitted ANSI colour escapes — even when the user redirected output to a file or pipeline, and even when `NO_COLOR=1` was set. [no-color.org](https://no-color.org/) has been the canonical opt-out env var since 2017; respecting it is one of the cheapest UX wins available. ## Change At the top of `keepopen.sh`, if either `NO_COLOR` is set OR stdout is not a TTY, all colour variables become empty strings. Banners and prefix labels become plain text — still loud and clearly labelled, just without escapes. \`\`\`bash if [[ -n "${NO_COLOR:-}" ]] || [[ ! -t 1 ]]; then C_RED='' C_YEL='' C_CYA='' C_GRN='' C_BOLD='' C_RST='' else # original ANSI definitions fi \`\`\` ## Verified \`\`\` $ NO_COLOR=1 keepopen.sh testapp /tmp false false | grep -c $'\033' 0 $ keepopen.sh testapp /tmp false false | grep -c $'\033' # piped → not TTY 0 \`\`\` Desktop-launch path keeps colour (real terminal, no `NO_COLOR`), so the on-screen failure banners are unchanged. The new behaviour only fires when: - User has `NO_COLOR` set globally (their explicit preference), or - Output is piped to a file / capture (CI logs, `tee`, `.log` redirects) ## Scope Touches `launcher/keepopen.sh` only — not part of the a2ml↔adoc lock-step group, so the gate in #172 does not fire on this PR. ## Coordination Independent of all other open launcher-standard PRs (#170, #171, #172, #173, #175) — different file, no conflicts in any merge order. ## Test plan - [x] `NO_COLOR=1` produces zero ANSI escapes - [x] Pipe (non-TTY stdout) produces zero ANSI escapes - [x] Default TTY behaviour unchanged (loud red/yellow banners) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b562ba1 commit a12f765

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

launcher/keepopen.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ GUI_CMD="${3:?keepopen: GUI_CMD required (arg 3) — pass '' if not applicable}"
3838
TUI_CMD="${4:?keepopen: TUI_CMD required (arg 4) — pass '' if not applicable}"
3939
LOG_FILE="${5:-}"
4040

41-
C_RED=$'\033[1;31m'
42-
C_YEL=$'\033[1;33m'
43-
C_CYA=$'\033[1;36m'
44-
C_GRN=$'\033[1;32m'
45-
C_BOLD=$'\033[1m'
46-
C_RST=$'\033[0m'
41+
# Honour NO_COLOR (https://no-color.org/) and auto-detect non-TTY stdout.
42+
# When set, banners and prefix labels emit no ANSI escapes — still loud
43+
# and clearly labelled, just plain text. The freedesktop-style desktop
44+
# launch redirects stdout to a real terminal so this rarely triggers
45+
# automatically, but covers `keepopen.sh ... | tee` and CI captures.
46+
if [[ -n "${NO_COLOR:-}" ]] || [[ ! -t 1 ]]; then
47+
C_RED='' C_YEL='' C_CYA='' C_GRN='' C_BOLD='' C_RST=''
48+
else
49+
C_RED=$'\033[1;31m'
50+
C_YEL=$'\033[1;33m'
51+
C_CYA=$'\033[1;36m'
52+
C_GRN=$'\033[1;32m'
53+
C_BOLD=$'\033[1m'
54+
C_RST=$'\033[0m'
55+
fi
4756

4857
banner() {
4958
# $1 = colour; $2 = title; remaining args = body lines.

0 commit comments

Comments
 (0)