aboutsummaryrefslogtreecommitdiff
path: root/vterm.el
diff options
context:
space:
mode:
authorIllia Ostapyshyn <ilya.ostapyshyn@gmail.com>2023-09-23 00:32:10 +0200
committerGabriele Bozzola <sbozzolator@gmail.com>2024-01-02 08:40:56 -0800
commite96c53f5035c841b20937b65142498bd8e161a40 (patch)
treef713a12fc39cef51e980c48040a7a98341122137 /vterm.el
parentf76de08cf62722a8c532b889a9361bbcc5c83972 (diff)
Differentiate foreground and background colors
Allow using different background and foreground colors for same ANSI index, analogously to how term-mode does it. Remove magical indices for underlined cells with default foreground and inverse-video cells with default background. Instead, pass relevant info to lisp function to handle these cases at higher level. * elisp.c, elisp.h (Fapply): New binding. (vterm_get_color): Add new argument for optional attributes. * vterm-module.c (cell_rgb_color): Pass relevant attributes to vterm_get_color. * vterm.el (vterm--get-color): Use foreground or background color of the face depending on received attributes. * README.md: Update documentation
Diffstat (limited to 'vterm.el')
-rw-r--r--vterm.el40
1 files changed, 21 insertions, 19 deletions
diff --git a/vterm.el b/vterm.el
index 8c56e08..ebb5b2a 100644
--- a/vterm.el
+++ b/vterm.el
@@ -1654,25 +1654,27 @@ If N is negative backward-line from end of buffer."
(when raw-pwd
(vterm--get-directory raw-pwd)))))
-(defun vterm--get-color (index)
- "Get color by index from `vterm-color-palette'.
-Argument INDEX index of the terminal color.
-Special values for INDEX are:
--11 foreground for cells with underline attribute, foreground of
-the `vterm-color-underline' face is used in this case.
--12 background for cells with inverse video attribute, background
-of the `vterm-color-inverse-video' face is used in this case."
- (cond
- ((and (>= index 0) (< index 16))
- (face-foreground
- (elt vterm-color-palette index)
- nil 'default))
- ((= index -11)
- (face-foreground 'vterm-color-underline nil 'default))
- ((= index -12)
- (face-background 'vterm-color-inverse-video nil 'default))
- (t
- nil)))
+(defun vterm--get-color (index &rest args)
+ "Get color by INDEX from `vterm-color-palette'.
+
+Special INDEX of -1 is used to represent default colors. ARGS
+may optionally contain `:underline' or `:inverse-video' for cells
+with underline or inverse video attribute. If ARGS contains
+`:foreground', use foreground color of the respective face
+instead of background."
+ (let ((foreground (member :foreground args))
+ (underline (member :underline args))
+ (inverse-video (member :inverse-video args)))
+ (funcall (if foreground #'face-foreground #'face-background)
+ (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)
+ (t 'default))
+ nil 'default)))
(defun vterm--eval (str)
"Check if string STR is `vterm-eval-cmds' and execute command.