Skip to content

[cli] Print status at intervals when no TTY#4819

Closed
ShadiBahaa wants to merge 1 commit intocanonical:mainfrom
ShadiBahaa:cli-non-tty-spinner-output
Closed

[cli] Print status at intervals when no TTY#4819
ShadiBahaa wants to merge 1 commit intocanonical:mainfrom
ShadiBahaa:cli-non-tty-spinner-output

Conversation

@ShadiBahaa
Copy link
Copy Markdown
Contributor

@ShadiBahaa ShadiBahaa commented Apr 14, 2026

Summary

When stdout is not a TTY (e.g. in CI pipelines, integration tests, or piped output), the AnimatedSpinner unconditionally outputs ANSI escape codes and backspace characters. This produces garbled or silent output, making it difficult to monitor progress or debug issues in headless environments.

This PR makes the spinner TTY-aware:

  • Adds an is_live parameter to AnimatedSpinner that indicates whether stdout is a terminal
  • When live (TTY): behavior is unchanged (animated spinner with ANSI escape codes)
  • When not live (no TTY): prints the status message as a plain-text line, followed by periodic dots every 5 seconds to indicate activity. No ANSI escape codes are emitted.
  • All CLI commands now pass term->cout_is_live() when constructing the spinner, using the existing Terminal TTY-detection infrastructure (POSIX isatty() on Unix, GetConsoleScreenBufferInfo() on Windows)

Test plan

  • Existing unit tests in test_common_callbacks.cpp continue to pass
  • Run a CLI command (e.g. multipass start) in a terminal and verify the animated spinner still works
  • Pipe a CLI command through another process (e.g. multipass start 2>&1 | cat) and verify plain-text output with no ANSI escape codes

Closes #2939

When stdout is not a TTY, the animated spinner outputs ANSI
escape codes that produce garbled output. This makes
integration test output silent and hard to debug.

Detect non-TTY via the existing Terminal::cout_is_live()
and fall back to printing plain-text status lines with
periodic dots instead of the animated spinner.

Closes: canonical#2939
@xmkg
Copy link
Copy Markdown
Member

xmkg commented Apr 15, 2026

Duplicate of #4706.

@ricab
Copy link
Copy Markdown
Collaborator

ricab commented Apr 15, 2026

Hi @ShadiBahaa, there is a PR already in flight to address this, as @xmkg pointed out above.

@ShadiBahaa ShadiBahaa closed this Apr 15, 2026
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.

[cli] When no TTY, print information in intervals instead of spinner

3 participants