Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LennartC
Copy link

@LennartC LennartC commented Nov 16, 2023

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

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (3d3b320) 4.86% compared to head (1372939) 3.12%.

Files 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 Sentry.
📢 Have feedback on the report? Share it here.

@MarvinJWendt
Copy link
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
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