onepub-dev / onepub-dev/dcli

Unexpected side affect of Ansi.isSupported checking terminal.

Open
#149 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
265
Forks
30
PR merge metrics
No merged PRs in 30d

Description

The method Ansi.isSupported checks if a ansi escape sequences are supported on the current terminal.

To make this more reliable it now checks if a terminal is attached by calling stdout.isTerminal.

This has worked well.

However there was an unexpected side effect.

If you run'

final list = start('some command', progress: Progress.capture()).toList();
print(list);

The previously the printed list included any ansi coloring.
With the new Ansi.isSupported check the output of any colour escape codes is suppressed because there is no terminal attached (we are capturing the output to a list).
This is not what I would normally want.
I'm think that we change the colour methods so the still output ansi escape sequences even if a terminal isn't attached.
This has the down side that we get colours logged to log files.
We do have the Ansi.strip() method that strips out colour which can be used as a filter when logging.

Discussion welcomed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Ansi.isSupported and its stdout.isTerminal check, then inspect the colour methods and the example using start with Progress.capture().toList(). Compare captured output with and without a terminal, and use Ansi.strip() as the reference for the expected logging workaround; the desired behavior still needs confirmation because the issue invites discussion.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.