4 ms·
I didn’t see it mentioned in the article so I’ll say it here: Please please please don’t using anything more than the 8 (plus 8 “bright”) colours when doing te
by hnlmorg 6y ago
I didn’t see it mentioned in the article so I’ll say it here:
Please please please don’t using anything more than the 8 (plus 8 “bright”) colours when doing text interfaces in the terminal. The reason being that the 8 colour palettes are defined by the terminal emulator where as the 256 (and other ANSI palettes not discussed in that article) are defined by the programmer.
Why does this matter? Simply because not everyone uses the same terminal colour scheme. If a programmer chooses a colour from the 8 colour palette then your terminal will (hopefully) render the text in a colour that’s distinct enough from the other text and background colours to be readable. However if you, as a programmer, choose the colour yourself there will be a great many terminal configurations where the colour you’ve chosen isn’t readable.
For example not everyone has a black background. macOS Terminal defaults to white whereas I tend to use Solarised Dark colour schemes that are more of a plum colour.
- mfontani 6y agoWhen I need my programs to use specific colors, I tend to use the RGB variety - which works regardless of preferences: "\e[0;48;2;R;G;Bm" While my "color1" might be different than yours, terminals don't usually fiddle with RGB.
- hnlmorg 6y agoThat'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).
- antihero 6y agoPlease don't do this, please let us look at your program in whatever colours we want to.
- albertzeyer 6y agoEven the 8 colors can be suboptimal depending on the scheme. E.g. Vim and Emacs try to determine whether your terminal background is light or dark, and use a somewhat different scheme depending on that. However, determining whether it is light or dark is not straight forward. I did some research on how other tools (Vim, Emacs, many others) do it: https://stackoverflow.com/a/54652367/133374 https://stackoverflow.com/a/54652367/133374