akermu / emacs-libvterm

Emacs libvterm integration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Foreground Face of Vterm always matches the background color in Doom Emacs

pramatias opened this issue · comments

Hello, in Ubuntu 22.04 i installed Doom Emacs 29, and emacs-libvterm from the apt package manager. Vterm tried to compile the module and it failed, i apt-get installed the module and set the path to init.el, and vterm works.

The foreground color however always matches perfectly with the background color of the theme. When i try to highlight with the mouse the output of vterm, it illuminates what is otherwise invisible, and when the highlight is removed it matches fg color matches again perfectly with the background color. That is true for the output and the input of the terminal. The command prompt text has no problem.

Also the output is not always hidden, some parts of the output might be visible. For example when i run exa which colorizes the output of the text, only some parts of the output has fg face exactly like the background color, and that causes them to be hidden.

No matter the theme, the fg-color matches always the background color. It's the same even for disable-theme.

Two images, one highlighted, one disabled theme colors.

image

image

commented

Same here on Vanilla Emacs. Sadly it is unusable due to this. Has anyone found a way to work around this issue?

commented

Ok I fixed it on NixOS by using the unstable version of the package

For those who struggle with this issue, I have fixed it by overriding the original vterm--get-color:

(defun km-vterm--get-color (index &rest args)
  "Retrieve the color by INDEX from `vterm-color-palette'.

A special INDEX of -1 refers to the default colors. ARGS can
optionally include `:underline’ or `:inverse-video’ to indicate
cells with these attributes. If ARGS contains `:foreground',
return the foreground color of the specified face instead of the
background color.

This function addresses an issue where the foreground color in
vterm may match the background color, rendering text invisible."
  (let ((foreground    (member :foreground args))
        (underline     (member :underline args))
        (inverse-video (member :inverse-video args)))
    (let* ((fn (if foreground #'face-foreground #'face-background))
           (base-face
            (cond ((and (>= index 0)
                        (< index 16))
                   (elt vterm-color-palette index))
                  ((and (= index -1) foreground
                        underline)
                   'vterm-color-underline)
                  ((and (= index -1)
                        (not foreground)
                        inverse-video)
                   'vterm-color-inverse-video)
                  ((and (= index -2))
                   'vterm-color-inverse-video))))
      (if base-face
          (funcall fn base-face nil t)
        (if (eq fn 'face-background)
            (face-foreground 'default)
          (face-background 'default))))))

(advice-add 'vterm--get-color :override #'km-vterm--get-color)

This solution works well for my setup, but other users may need to adjust it further based on their specific configuration or themes.

I have the similar problem, and cannot even change the background color. How do you change the background in vterm?