reddit / emacs

Why are colours different in vterm, term and my OS terminal xfce4-terminal?

bhrgunatha · 2022-10-22 13:20
`term` has settings for 'bright' colours. Here's mine: (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(term-color-black ((t (:background "#2e3436" :foreground "#000000")))) '(term-color-blue ((t (:background "#8D37AF" :foreground "#8D37AF")))) '(term-color-bright-black ((t (:background "#777979" :foreground "#777979")))) '(term-color-bright-blue ((t (:background "#5ba0f4" :foreground "#5ba0f4")))) '(term-color-bright-cyan ((t (:background "#8CD5CF" :foreground "#8CD5CF")))) '(term-color-bright-green ((t (:background "#37A42B" :foreground "#37A42B")))) '(term-color-bright-magenta ((t (:background "#f692dd" :foreground "#f692dd")))) '(term-color-bright-red ((t (:background "#ff9000" :foreground "#ff9000")))) '(term-color-bright-white ((t (:background "#f3f3f3" :foreground "#f3f3f3")))) '(term-color-bright-yellow ((t (:background "#ffd500" :foreground "#ffd500")))) '(term-color-cyan ((t (:background "#17b2b2" :foreground "#17b2b2")))) '(term-color-green ((t (:background "#00bf00" :foreground "#00bf00")))) '(term-color-magenta ((t (:background "#e85290" :foreground "#e85290")))) '(term-color-red ((t (:background "#fe6363" :foreground "#fe6363")))) '(term-color-white ((t (:background "#d2d7cf" :foreground "#d2d7cf")))) '(term-color-yellow ((t (:background "#f2c300" :foreground "#f2c300")))) '(term-default-bg-color ((t (:inherit term-color-black)))) '(term-default-fg-color ((t (:inherit term-color-white))))) [Here's a screenshot of it rendered using `rainbow-mode`](https://i.imgur.com/lEsy3xM.png) I've set these to match my OS terminal (xfce4-terminal) exactly. Here's are some screenshots of the output of `ls -l --color`: * [using my OS terminal](https://i.imgur.com/0Bwxoq6.png) * [inside emacs using `term`](https://i.imgur.com/dPUiWoo.png) * [inside emacs using `vterm`](https://i.imgur.com/44o9LTB.png) Why are the colours in `term` and `vterm` different my OS terminal? xfce4-terminal has a setting 'Show bold text in bright colours' - that I've selected. If I de-select that setting, the colours match the ones I see in `vterm` and `term`. It seems that neither `term` nor `vterm` are using the 'bright' colours for bold text. Is it possible to get them to use those bright colours for bold? Why are there `term` faces for bright colours if they aren't being used?
[deleted] · 2022-10-22 13:54
[deleted]
vfclists · 2022-10-25 07:52
This is more likely to do with the right TERM values in the terminal you are using. Check the output of `echo $TERM` in those terminals. They may be different and the `$TERM`.terminfo settings for each of them may be different even if they have the same `TERM`.terminfo values. Getting colours to show properly in terminals is a complicated topic and gets more so with 24bit color terminals. Do some googling.
bhrgunatha · 2022-10-25 09:33
>This is more likely to do with the right TERM values in the terminal you are using. I don't think that's the issue, but: xfce-terminal: xterm-256color vterm: xterm-256color term: eterm-color I think the issue is that xfce4-terminal is receiving signals/commands to show (what it terms as) bold colours and is using the "bright" colours according to its 'Show bold text in bright colours' option. I'm not sure what the difference between bold and bright colours are. I don't think vterm or term are converting the bold colour signals/commands they receive to use their defined bright colours. > Do some googling. This is not helpful. What makes you think I haven't tried?
bhrgunatha · 2022-11-03 14:09
News just in from department of Answering your own stupid questions. --- **tl;dr** I solved all of the colour discrepancy by changing my colour scheme**s**, removing the **bold as bright** options and I also had to change my OS terminal prompt configuration. --- An *ass*ide: There is some minor controversy over the [render bold as bright option](https://github.com/kovidgoyal/kitty/issues/512), but since so many terminal emulators implement it, it seems a tad churlish not to offer a configuration option to match the other implementations. Still, [bureaucrat Kovid is technically correct](https://www.youtube.com/watch?v=hou0lU8WMgo) and in order to save myself some future confusion, I've turned off the option for using bold as bright and changed the colour settings everywhere as a result. --- **Configuration changes.** My preference is for high contrast colours because my sight isn't great. To do that I swapped some regular colour for their bright counterpart in `~/.config/xfce4/terminal/colorthemes/terminalrc`. I removed the `custom-set-faces` settings for all `term-color-...` faces and added this to my configuration: (defmacro def-term-colour (mode face &rest attrs) (let ((mode-face (intern (concat (symbol-name mode) "-color-" (symbol-name face))))) `(set-face-attribute ',mode-face nil ,@attrs))) (use-package ansi-color :ensure nil :config (def-term-colour ansi black :foreground "#2e3436" :background "#2e3436") (def-term-colour ansi red :foreground "#fe6363" :background "#fe6363") (def-term-colour ansi green :foreground "#2cde2c" :background "#2cde2c") (def-term-colour ansi yellow :foreground "#f2c300" :background "#f2c300") (def-term-colour ansi blue :foreground "#5ba0f4" :background "#5ba0f4") (def-term-colour ansi magenta :foreground "#e288cc" :background "#e288cc") (def-term-colour ansi cyan :foreground "#8cd5cf" :background "#8cd5cf") (def-term-colour ansi white :foreground "#d2d7cf" :background "#d2d7cf") (def-term-colour ansi bright-black :foreground "#777979" :background "#777979") (def-term-colour ansi bright-red :foreground "#ff9000" :background "#ff9000") (def-term-colour ansi bright-green :foreground "#37a42b" :background "#37a42b") (def-term-colour ansi bright-yellow :foreground "#ffd500" :background "#ffd500") (def-term-colour ansi bright-blue :foreground "#8d37af" :background "#8d37af") (def-term-colour ansi bright-magenta :foreground "#e85290" :background "#e85290") (def-term-colour ansi bright-cyan :foreground "#17b2b2" :background "#17b2b2") (def-term-colour ansi bright-white :foreground "#f3f3f3" :background "#f3f3f3") (setq ansi-color-bold-is-bright nil)) (use-package term :ensure nil :hook (term-mode-hook . b/configure-term) :config (def-term-colour term black :foreground "#2e3436" :background "#2e3436") (def-term-colour term red :foreground "#fe6363" :background "#fe6363") (def-term-colour term green :foreground "#2cde2c" :background "#2cde2c") (def-term-colour term yellow :foreground "#f2c300" :background "#f2c300") (def-term-colour term blue :foreground "#5ba0f4" :background "#5ba0f4") (def-term-colour term magenta :foreground "#e288cc" :background "#e288cc") (def-term-colour term cyan :foreground "#8cd5cf" :background "#8cd5cf") (def-term-colour term white :foreground "#d2d7cf" :background "#d2d7cf") (def-term-colour term bright-black :foreground "#777979" :background "#777979") (def-term-colour term bright-red :foreground "#ff9000" :background "#ff9000") (def-term-colour term bright-green :foreground "#37a42b" :background "#37a42b") (def-term-colour term bright-yellow :foreground "#ffd500" :background "#ffd500") (def-term-colour term bright-blue :foreground "#8d37af" :background "#8d37af") (def-term-colour term bright-magenta :foreground "#e85290" :background "#e85290") (def-term-colour term bright-cyan :foreground "#17b2b2" :background "#17b2b2") (def-term-colour term bright-white :foreground "#f3f3f3" :background "#f3f3f3") (set-face-attribute 'term nil :foreground "#b2b2b2" :background "#202020") (setq explicit-shell-file-name "/bin/zsh")) (use-package vterm :config (add-hook 'vterm-mode-hook #'b/configure-term) ;; The vterm package only uses a colour palette of 8 colours, inheriting term-color black..white (0-7) ;; and ignores standard SGR color codes for 8-bit colours 38;5;<n> and 48;5;<n> ;; - https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit ;; Instead vterm uses the face's :foreground attribute for colour index 0-7 ;; and the :background attribute for colour index 8-15 ;; https://github.com/akermu/emacs-libvterm/blob/2681120b770573044832ba8c22ccbac192e1a294/vterm.el#L414 (def-term-colour vterm black :foreground "#2e3436" :background "#777979") (def-term-colour vterm red :foreground "#fe6363" :background "#ff9000") (def-term-colour vterm green :foreground "#2cde2c" :background "#37a42b") (def-term-colour vterm yellow :foreground "#f2c300" :background "#ffd500") (def-term-colour vterm blue :foreground "#5ba0f4" :background "#8d37af") (def-term-colour vterm magenta :foreground "#e288cc" :background "#e85290") (def-term-colour vterm cyan :foreground "#8cd5cf" :background "#17b2b2") (def-term-colour vterm white :foreground "#d2d7cf" :background "#f3f3f3") (setq vterm-max-scrollback 10000 vterm-timer-delay 0.032 vterm-clear-scrollback-when-clearing t)) > Hey bhrgunatha, why didn't you just set the `term-mode` faces? Glad you asked. `term-modes` faces all inherit from `ansi-color` and `term-mode` also checks `ansi-color-bold-is-bright` to choose which face to use. I also discovered that some emacs colour themes configure both `ansi-color` **and** `term-mode`. Now, _\*sigh\*_ you'll notice too that `vterm` is that special kid in the corner. It only has 8 faces and you need to set each face's `:foreground` attribute for the regular colours (0-7) and the `:background` attribute for the bright colours (8-15). # Finally ...after all that * [xfce4-terminal:](https://i.imgur.com/OPcCjxJ.png) * [emacs term:](https://i.imgur.com/MjHseas.png) * [emacs vterm:](https://i.imgur.com/PWc7ore.png) * [For fun, using kitty:](https://i.imgur.com/LHNgQgY.png), since I'm thinking of using kitty to replace `xfce4-terminal`. I say _**after all that**_ because I only arrived at this solution through a circuitous route delving through the code of `term` and `ansi-color` and reading page after page about ansi and escape sequences and SGR codes and trying different scripts to show terminal colour capabilities. If you want **those** *gory* details, you'll have to be nice and ask.