-
Notifications
You must be signed in to change notification settings - Fork 49
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
Check isatty == false before coloring #54
Comments
Sounds useful. However, we'd probably want to return an error when the user attempts to create the terminal instead of not colorizing. |
Color output may be desired when not attached to a tty (ex, |
Good point. However, this is a rare edge case and doesn't even work in WinConsole.
We already do this. |
A similar issue turned up in another library that uses this project. Perhaps the Terminal object returned by stdout() should have a isatty flag/attribute that can be checked. This would allow the caller to check both if the terminal supports colours, and whether it's being output directly to the terminal. |
This could require a significant change to the API (although that might not be a bad idea) because there's no way to get a file descriptor/file handle from an |
In my opinion |
@retep998 are there any terminals that support both? Unfortunately, the windows console API does not support bold, underline, or italics so I'd rather use terminfo if supported. |
In order to support the Windows console API you need to be the windows console. If you are the Windows console then you are incapable of displaying any sort of styling that the Windows console does not support, unless you do incredibly hacky things hooking into the Windows console. I personally don't know of any terminals that are capable of supporting the Windows console API but with the ability to display additional styling. |
@retep998 I read somewhere that Windows 10 consoles support ANSI escape sequences. Would trying terminfo first be fine now? |
@tbu- No. The Windows 10 console is still not a terminfo terminal, it is just the Windows console with optional ANSI escape sequence support. Instead you'd first detect whether it is a Windows console, and you'd attempt to set the console mode to enable ANSI escape sequences. If that works, then you can use ANSI escape sequences. If you can't set that console mode but it still is a Windows console then your only option is standard windows console functions |
Please don't automagic |
Hi!
I've found this library as an excellent solution to colorize the logging output. However, when the stdout/stderr is redirected somewhere else (
./a.out > log.txt
for example) the final output is still mangled with terminal special characters as an opposite expected behavior.It's a common practice in Unix to check
isatty
function before trying to colorize, see man for more. Moreover theisatty
function is associated with terminal as like as this crate, so it may be useful to add it.I can implement this functionality if you agree. Thoughts?
The text was updated successfully, but these errors were encountered: