2 ms·
That's the exact opposite of my plee. If you're drawing graphics to the screen or something else that's dependant on being colour accurate, then what you say is
by hnlmorg 6y ago
That's the exact opposite of my plee. If you're drawing graphics to the screen or something else that's dependant on being colour accurate, then what you say is fine. But the overwhelming majority of CLI tools aren't. My point was that for regular command line / TUIs, the programmer should not chose specific colours and instead respect the terminal preferences of the users. Terminal preferences differ wildly and you may quickly find people cannot use your terminal app because it is unreadable on their terminal.
You'd be surprised just how wildly different some peoples preferences are. For example I know of people who choose different colour schemes for a DB server (red background) vs a web server (green background). Or a dev server vs prod server. Myself, I choose a non-black background due to dyslexia (coloured background are easier for me to read than black backgrounds). Others might have chosen a non-default background colour to reduce eye strain.
CLI don't need to be artistically brilliant and for a great many people it's an essential productivity tool. So please don't impose your preferences onto others. If developers want to add their own design flair to UIs then they can expose a HTTP endpoint as well, or even an optional "--true-colour" flag or similar environmental variable. But if they want to release a UNIX-like CLI tool then please stick to 8+bright colours by default.
## TTYs
Also, while one this topic, if anyone does add colours by default (even if it is just the 8+bright) then also please check that the output terminal is a TTY. If it isn't then please don't output any ANSI escape sequences at all. This is so that your application works being piped. eg
# foo's STDOUT is a TTY
$ foo
# foo's STDOUT is not a TTY
$ foo | grep bar
In the later example, if you're not detecting whether STDOUT is a TTY and subsequently not including ANSI escape sequences then `grep` (et al) will receive them and that could cause weird behaviour in the subsequent applications (I do appreciate there are occasions when you do specifically want to pipe ANSI escape sequences. But those occasions are less common than the UNIX norm of auto-disabling escape sequences when STDOUT != TTY).