aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md27
-rw-r--r--elisp.c1
-rw-r--r--elisp.h3
-rw-r--r--vterm-module.c11
-rw-r--r--vterm.el99
5 files changed, 117 insertions, 24 deletions
diff --git a/README.md b/README.md
index 487933c..308621b 100644
--- a/README.md
+++ b/README.md
@@ -77,22 +77,17 @@ bound to `C-c C-c`.
Set the `:foreground` and `:background` attributes of the following faces to a
color you like:
-- vterm-color-default-fg
-- vterm-color-default-bg
-- vterm-color-black-fg
-- vterm-color-black-bg
-- vterm-color-red-fg
-- vterm-color-green-bg
-- vterm-color-green-fg
-- vterm-color-yellow-bg
-- vterm-color-blue-fg
-- vterm-color-blue-bg
-- vterm-color-magenta-fg
-- vterm-color-magenta-bg
-- vterm-color-cyan-fg
-- vterm-color-cyan-bg
-- vterm-color-white-fg
-- vterm-color-white-bg
+- vterm-color-default
+- vterm-color-black
+- vterm-color-black
+- vterm-color-red
+- vterm-color-green
+- vterm-color-yellow
+- vterm-color-blue
+- vterm-color-magenta
+- vterm-color-cyan
+- vterm-color-white
+
## Related packages
diff --git a/elisp.c b/elisp.c
index 951791f..9483692 100644
--- a/elisp.c
+++ b/elisp.c
@@ -113,7 +113,6 @@ emacs_value vterm_get_color(emacs_env *env, int index) {
emacs_value idx = env->make_integer(env, index);
return env->funcall(env, Fvterm_get_color, 1, (emacs_value[]){idx});
}
-
void set_title(emacs_env *env, emacs_value string) {
env->funcall(env, Fvterm_set_title, 1, (emacs_value[]){string});
}
diff --git a/elisp.h b/elisp.h
index f853b5b..6bb149c 100644
--- a/elisp.h
+++ b/elisp.h
@@ -22,7 +22,6 @@ emacs_value Qbox;
emacs_value Qbar;
emacs_value Qhbar;
emacs_value Qcursor_type;
-emacs_value Qansi_color_names_vector;
// Emacs functions
emacs_value Fsymbol_value;
@@ -48,6 +47,7 @@ emacs_value Fselected_window;
emacs_value Fvterm_set_title;
emacs_value Fvterm_invalidate;
emacs_value Feq;
+emacs_value Fvterm_get_color;
// Utils
void bind_function(emacs_env *env, const char *name, emacs_value Sfun);
@@ -75,5 +75,6 @@ emacs_value get_buffer_window(emacs_env *env);
emacs_value selected_window(emacs_env *env);
void set_title(emacs_env *env, emacs_value string);
void vterm_invalidate(emacs_env *env);
+emacs_value vterm_get_color(emacs_env *env, int index);
#endif /* ELISP_H */
diff --git a/vterm-module.c b/vterm-module.c
index 45b97b3..7d44293 100644
--- a/vterm-module.c
+++ b/vterm-module.c
@@ -491,16 +491,15 @@ static emacs_value render_text(emacs_env *env, Term *term, char *buffer,
static emacs_value color_to_rgb_string(emacs_env *env, Term *term,
VTermColor *color) {
- emacs_value palette = symbol_value(env, Qansi_color_names_vector);
if (VTERM_COLOR_IS_DEFAULT_FG(color)) {
- return env->vec_get(env, palette, 7);
+ return vterm_get_color(env, -1);
}
if (VTERM_COLOR_IS_DEFAULT_BG(color)) {
- return env->vec_get(env, palette, 0);
+ return vterm_get_color(env, -2);
}
if (VTERM_COLOR_IS_INDEXED(color)) {
if (color->indexed.idx < 16) {
- return env->vec_get(env, palette, color->indexed.idx % 8);
+ return vterm_get_color(env, color->indexed.idx);
} else {
VTermState *state = vterm_obtain_state(term->vt);
vterm_state_get_palette_color(state, color->indexed.idx, color);
@@ -736,8 +735,6 @@ int emacs_module_init(struct emacs_runtime *ert) {
Qbar = env->make_global_ref(env, env->intern(env, "bar"));
Qhbar = env->make_global_ref(env, env->intern(env, "hbar"));
Qcursor_type = env->make_global_ref(env, env->intern(env, "cursor-type"));
- Qansi_color_names_vector =
- env->make_global_ref(env, env->intern(env, "ansi-color-names-vector"));
// Functions
Fsymbol_value = env->make_global_ref(env, env->intern(env, "symbol-value"));
@@ -772,6 +769,8 @@ int emacs_module_init(struct emacs_runtime *ert) {
Fvterm_invalidate =
env->make_global_ref(env, env->intern(env, "vterm--invalidate"));
Feq = env->make_global_ref(env, env->intern(env, "eq"));
+ Fvterm_get_color =
+ env->make_global_ref(env, env->intern(env, "vterm--get-color"));
// Exported functions
emacs_value fun;
diff --git a/vterm.el b/vterm.el
index 108e36a..d8a8a26 100644
--- a/vterm.el
+++ b/vterm.el
@@ -120,6 +120,105 @@ for different shell"
:type 'hook
:group 'vterm)
+(defface vterm-color-default
+ `((t :inherit default))
+ "The default normal color and bright color.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-black
+ `((t :foreground ,(aref ansi-color-names-vector 0)
+ :background ,(aref ansi-color-names-vector 0)))
+ "Face used to render black color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-red
+ `((t :foreground ,(aref ansi-color-names-vector 1)
+ :background ,(aref ansi-color-names-vector 1)))
+ "Face used to render red color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-green
+ `((t :foreground ,(aref ansi-color-names-vector 2)
+ :background ,(aref ansi-color-names-vector 2)))
+ "Face used to render green color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-yellow
+ `((t :foreground ,(aref ansi-color-names-vector 3)
+ :background ,(aref ansi-color-names-vector 3)))
+ "Face used to render yellow color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-blue
+ `((t :foreground ,(aref ansi-color-names-vector 4)
+ :background ,(aref ansi-color-names-vector 4)))
+ "Face used to render blue color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-magenta
+ `((t :foreground ,(aref ansi-color-names-vector 5)
+ :background ,(aref ansi-color-names-vector 5)))
+ "Face used to render magenta color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-cyan
+ `((t :foreground ,(aref ansi-color-names-vector 6)
+ :background ,(aref ansi-color-names-vector 6)))
+ "Face used to render cyan color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defface vterm-color-white
+ `((t :foreground ,(aref ansi-color-names-vector 7)
+ :background ,(aref ansi-color-names-vector 7)))
+ "Face used to render white color code.
+the foreground color are used for normal color,
+and background color are used for bright color. "
+ :group 'vterm)
+
+(defvar vterm-color-palette
+ [vterm-color-black
+ vterm-color-red
+ vterm-color-green
+ vterm-color-yellow
+ vterm-color-blue
+ vterm-color-magenta
+ vterm-color-cyan
+ vterm-color-white]
+ "Color palette for the foreground and background.")
+
+(defun vterm--get-color(index)
+ "Get color by index from `vterm-color-palette'.
+Argument INDEX index of color."
+ (cond
+ ((and (>= index 0)(< index 8 ))
+ (face-foreground
+ (elt vterm-color-palette index)
+ nil 'default))
+ ((and (>= index 8 )(< index 16 ))
+ (face-background
+ (elt vterm-color-palette (% index 8))
+ nil 'default))
+ ( (= index -1) ;-1 foreground
+ (face-foreground 'vterm-color-default nil 'default))
+ (t ;-2 background
+ (face-background 'vterm-color-default nil 'default))))
+
(defvar-local vterm--term nil
"Pointer to Term.")