From 44570d15d220f5d41aa1ce20e84644bd7f891d54 Mon Sep 17 00:00:00 2001 From: jixiufeng Date: Mon, 22 Apr 2019 23:39:36 +0800 Subject: support xterm-256color --- vterm-module.c | 15 +++++++++------ vterm.el | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vterm-module.c b/vterm-module.c index 224ffcf..f753280 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -498,12 +498,15 @@ static emacs_value color_to_rgb_string(emacs_env *env, Term *term, if (VTERM_COLOR_IS_DEFAULT_BG(color)) { return env->vec_get(env, palette, 0); } - if (VTERM_COLOR_IS_INDEXED(color) < 16) { - return env->vec_get(env, palette, color->indexed.idx % 8); - } - if (VTERM_COLOR_IS_INDEXED(color) >= 16) { - VTermState *state = vterm_obtain_state(term->vt); - vterm_state_get_palette_color(state, color->indexed.idx, color); + if (VTERM_COLOR_IS_INDEXED(color)) { + if (color->indexed.idx < 16) { + return env->vec_get(env, palette, color->indexed.idx % 8); + } else { + VTermState *state = vterm_obtain_state(term->vt); + vterm_state_get_palette_color(state, color->indexed.idx, color); + } + } else if (VTERM_COLOR_IS_RGB(color)) { + /* do nothing just use the argument color directly */ } char buffer[8]; diff --git a/vterm.el b/vterm.el index 63ff177..108e36a 100644 --- a/vterm.el +++ b/vterm.el @@ -140,7 +140,7 @@ for different shell" (if (version< emacs-version "27") (add-hook 'window-size-change-functions #'vterm--window-size-change-26 t t) (add-hook 'window-size-change-functions #'vterm--window-size-change t t)) - (let ((process-environment (append '("TERM=xterm" + (let ((process-environment (append '("TERM=xterm-256color" "INSIDE_EMACS=vterm" "LINES" "COLUMNS") -- cgit v1.0 From d97260c902524850b4b90489231a3fe00f606921 Mon Sep 17 00:00:00 2001 From: jixiufeng Date: Mon, 22 Apr 2019 23:39:52 +0800 Subject: clean code,remove unused function get_hex_color_fg and get_hex_color_bg --- elisp.c | 11 +++-------- elisp.h | 3 --- vterm-module.c | 2 -- vterm-module.h | 10 ++++------ 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/elisp.c b/elisp.c index 3fe511f..951791f 100644 --- a/elisp.c +++ b/elisp.c @@ -109,14 +109,9 @@ void set_cursor_type(emacs_env *env, emacs_value QCursorType) { } -emacs_value get_hex_color_fg(emacs_env *env, emacs_value face) { - return env->funcall(env, Fvterm_face_color_hex, 2, - (emacs_value[]){face, Qforeground}); -} - -emacs_value get_hex_color_bg(emacs_env *env, emacs_value face) { - return env->funcall(env, Fvterm_face_color_hex, 2, - (emacs_value[]){face, Qbackground}); +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) { diff --git a/elisp.h b/elisp.h index 584a1d8..f853b5b 100644 --- a/elisp.h +++ b/elisp.h @@ -42,7 +42,6 @@ emacs_value Fpoint; emacs_value Fput_text_property; emacs_value Fset; -emacs_value Fvterm_face_color_hex; emacs_value Fvterm_flush_output; emacs_value Fget_buffer_window; emacs_value Fselected_window; @@ -66,8 +65,6 @@ void forward_line(emacs_env *env, int n); void goto_line(emacs_env *env, int n); void set_cursor_type(emacs_env *env, emacs_value cursor_type); void delete_lines(emacs_env *env, int linenum, int count, bool del_whole_line); -emacs_value get_hex_color_fg(emacs_env *env, emacs_value face); -emacs_value get_hex_color_bg(emacs_env *env, emacs_value face); emacs_value buffer_line_number(emacs_env *env); void recenter(emacs_env *env, emacs_value pos); void set_window_point(emacs_env *env, emacs_value win, emacs_value point); diff --git a/vterm-module.c b/vterm-module.c index f753280..45b97b3 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -749,8 +749,6 @@ int emacs_module_init(struct emacs_runtime *ert) { Fput_text_property = env->make_global_ref(env, env->intern(env, "put-text-property")); Fset = env->make_global_ref(env, env->intern(env, "set")); - Fvterm_face_color_hex = - env->make_global_ref(env, env->intern(env, "vterm--face-color-hex")); Fvterm_flush_output = env->make_global_ref(env, env->intern(env, "vterm--flush-output")); Fforward_line = env->make_global_ref(env, env->intern(env, "forward-line")); diff --git a/vterm-module.h b/vterm-module.h index 9ed1831..356a6dd 100644 --- a/vterm-module.h +++ b/vterm-module.h @@ -8,7 +8,6 @@ int plugin_is_GPL_compatible; - #define SB_MAX 100000 // Maximum 'scrollback' value. #ifndef MIN @@ -64,11 +63,10 @@ typedef struct Term { static bool compare_cells(VTermScreenCell *a, VTermScreenCell *b); static bool is_key(unsigned char *key, size_t len, char *key_description); -static emacs_value render_text(emacs_env *env, Term *term, char *string, int len, - VTermScreenCell *cell); -static emacs_value cell_to_face(emacs_env *env, Term *term, VTermScreenCell *cell); -static emacs_value color_to_face(emacs_env *env, VTermColor *color, emacs_value palette); -static emacs_value color_to_rgb_string(emacs_env *env, Term *term, VTermColor *color); +static emacs_value render_text(emacs_env *env, Term *term, char *string, + int len, VTermScreenCell *cell); +static emacs_value color_to_rgb_string(emacs_env *env, Term *term, + VTermColor *color); static int term_settermprop(VTermProp prop, VTermValue *val, void *user_data); -- cgit v1.0 From 8e5b0ac691485040ddf8c32a55bed045d37585c0 Mon Sep 17 00:00:00 2001 From: jixiufeng Date: Mon, 22 Apr 2019 23:51:45 +0800 Subject: update GIT_TAG of libvterm in CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 281c067..3d45441 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ if(USE_SYSTEM_LIBVTERM) else() ExternalProject_add(libvterm GIT_REPOSITORY https://github.com/neovim/libvterm.git - GIT_TAG a6293a0e033e7e86c74889b4527787993656883a + GIT_TAG 89675ffdda615ffc3f29d1c47a933f4f44183364 CONFIGURE_COMMAND "" BUILD_COMMAND make "CFLAGS='-fPIC'" BUILD_IN_SOURCE ON -- cgit v1.0 From afd9213af3481f34a1afdd1be87507c7393ef3fa Mon Sep 17 00:00:00 2001 From: jixiufeng Date: Tue, 23 Apr 2019 23:27:58 +0800 Subject: add more faces,for example vterm-color-default vterm-color-black --- README.md | 27 +++++++--------- elisp.c | 1 - elisp.h | 3 +- vterm-module.c | 11 +++---- vterm.el | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 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.") -- cgit v1.0 From 7ded6fb574ae183e2971717553e42d1961be1dce Mon Sep 17 00:00:00 2001 From: jixiuf Date: Fri, 12 Jul 2019 07:18:55 +0800 Subject: inherited color from term.el instead of ansi-color --- vterm.el | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/vterm.el b/vterm.el index d8a8a26..f233f92 100644 --- a/vterm.el +++ b/vterm.el @@ -42,7 +42,7 @@ ;;; Code: -(require 'ansi-color) +(require 'term) (defvar vterm-install-buffer-name " *Install vterm" "Name of the buffer used for compiling vterm-module.") @@ -128,64 +128,56 @@ 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))) + `((t :inherit term-color-black)) "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))) + `((t :inherit term-color-red)) "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))) + `((t :inherit term-color-green)) "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))) + `((t :inherit term-color-yellow)) "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))) + `((t :inherit term-color-blue)) "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))) + `((t :inherit term-color-magenta)) "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))) + `((t :inherit term-color-cyan)) "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))) + `((t :inherit term-color-white)) "Face used to render white color code. the foreground color are used for normal color, and background color are used for bright color. " @@ -406,7 +398,7 @@ Then triggers a redraw from the module." (vterm--write-input vterm--term input) (vterm--update vterm--term))))) -(defun vterm--sentinel (process event) +(defun vterm--sentinel (process _event) "Sentinel of vterm PROCESS. Argument EVENT process event." (let ((buf (process-buffer process))) -- cgit v1.0 From f3e68ea809adb3df1e7bb4cd95f78bc913102854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BCrmetz?= Date: Tue, 30 Jul 2019 16:09:24 +0200 Subject: Order variables and functions --- vterm.el | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/vterm.el b/vterm.el index f233f92..560aa75 100644 --- a/vterm.el +++ b/vterm.el @@ -194,29 +194,19 @@ and background color are used for bright color. " 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.") (defvar-local vterm--process nil "Shell process of current term.") +(defvar-local vterm--redraw-timer nil) + +(defvar vterm-timer-delay 0.01 + "Delay for refreshing the buffer after receiving updates from libvterm. +Improves performance when receiving large bursts of data. +If nil, never delay") + (define-derived-mode vterm-mode fundamental-mode "VTerm" "Major mode for vterm buffer." (buffer-disable-undo) @@ -336,13 +326,6 @@ Optional argument PASTE-P paste-p." (when paste-p (vterm--update vterm--term "" nil nil nil)))) -(defvar-local vterm--redraw-timer nil) - -(defvar vterm-timer-delay 0.01 - "Delay for refreshing the buffer after receiving updates from libvterm. -Improves performance when receiving large bursts of data. -If nil, never delay") - (defun vterm--invalidate() "The terminal buffer is invalidated, the buffer needs redrawing." (if vterm-timer-delay @@ -452,6 +435,22 @@ Feeds the size change to the virtual terminal." "Run the `vterm--set-title-hook' with TITLE as argument." (run-hook-with-args 'vterm-set-title-functions title)) +(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)))) (provide 'vterm) ;;; vterm.el ends here -- cgit v1.0