-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
use tput or similar #247
Comments
As the pioneer of this topic, I can add that after implementing In addition to already mentioned benefits, a specific scenario improved via the use of
This is the output with
This behavior is largely explained in the first post under "Portability" but to add more resolution — in a limited environment where terminal output is not expected or needed, |
Thanks for adding extra context. I also have an observation to make after trying out tput, the GitHub actions went from being colored to black and white. The truth is that color in actions helps with reading them since a very common use of bashunit is precisely its execution during CI/CD. |
Yes, that is the effect of There is surely a middle ground but it has not revealed itself yet. |
Ok, I've figured out a way to serve my usecase and leave the rest intact. The solution is to slightly modify the function I added here so whenever Lines 9 to 18 in 4613813
This should keep colors in every other scenario, even when sgr() {
- local codes=${1:-0}
+ local codes return
+
+ codes=${1:-0}
shift
for c in "$@"; do
codes="$codes;$c"
done
- echo $'\e'"[${codes}m"
+ return=$'\e'"[${codes}m"
+
+ if [[ $TERM == 'dumb' ]]; then
+ return=""
+ fi
+
+ echo "$return"
} Simple as that, let me know if a PR like that would be welcome! |
Thanks, @h0adp0re ! Feel free to create a PR and we can continue the conversation from there 👍🏼 |
@h0adp0re ping on this one? :) |
Original idea: #247 (comment) Co-authored-by: h0adp0re <[email protected]>
Using tput instead of direct ANSI escape sequences for changing text and background colors offers several advantages:
In summary, tput offers a safer, more portable, and maintainable solution for terminal manipulation than hard-coding ANSI escape sequences.
But not everything that glitters is gold; in PR #245, we saw that a large number of tests failed or became inconsistent across different environments, which really makes us reconsider how to implement these kinds of tools. Therefore, we need to study whether we want to use tput or some alternative and how to do so in a way that does not reduce the reliability of bashunit.
The text was updated successfully, but these errors were encountered: