Skip to content

ANSI escape codes should only be written if writer is a TTY - #23

Open
LennartC wants to merge 1 commit into
atomicgo:mainfrom
LennartC:main
Open

ANSI escape codes should only be written if writer is a TTY#23
LennartC wants to merge 1 commit into
atomicgo:mainfrom
LennartC:main

Conversation

@LennartC

@LennartC LennartC commented Nov 16, 2023

Copy link
Copy Markdown

ANSI escape codes should only be written when the writer is a terminal.

This is important when the output is redirect to a file for example.

This would solve #24

@codecov

codecov Bot commented Nov 16, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 5.55556% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 3.12%. Comparing base (3d3b320) to head (1372939).
⚠️ Report is 45 commits behind head on main.

Files with missing lines Patch % Lines
cursor_other.go 5.55% 15 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main     #23      +/-   ##
========================================
- Coverage   4.86%   3.12%   -1.74%     
========================================
  Files          6       6              
  Lines        185     192       +7     
========================================
- Hits           9       6       -3     
- Misses       176     184       +8     
- Partials       0       2       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MarvinJWendt

Copy link
Copy Markdown
Member

Hi, thanks for the PR! We should still have a way to force ANSI codes, even if it is a file. Sometimes the user might want to record the ANSI codes to debug a problem, or to validate tests. We should either have something like var Force bool or we could let the user handle the logic by providing a method to turn off ANSI output.

@LennartC

Copy link
Copy Markdown
Author

Not entirely sure how to fix this then.
If you want to let the user handle it, I see the following options:

  1. make the cursor's writer public, so the user can implement an IsTerminal himself and decide whether to call Hide, Show, ...
  2. keep the new IsTerminal method in cursor, and make it public.
  3. not care at all in this module, and then if the user wants to handle it, he'll have to explicitly set the writer of the cursor.
  4. Or, as you suggested, add a Force flag.

Let me know what you prefer and I'll update the PR ;-)

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.

2 participants