ANSI escape codes should only be written if writer is a TTY
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 https://github.com/atomicgo/cursor/issues/24
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 :warning: |
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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.
Not entirely sure how to fix this then. If you want to let the user handle it, I see the following options:
- make the cursor's writer public, so the user can implement an IsTerminal himself and decide whether to call Hide, Show, ...
- keep the new IsTerminal method in cursor, and make it public.
- 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.
- Or, as you suggested, add a Force flag.
Let me know what you prefer and I'll update the PR ;-)