diff options
| -rw-r--r-- | elisp.c | 6 | ||||
| -rw-r--r-- | elisp.h | 5 | ||||
| -rw-r--r-- | vterm-module.c | 52 | ||||
| -rw-r--r-- | vterm-module.h | 12 |
4 files changed, 64 insertions, 11 deletions
@@ -98,13 +98,11 @@ emacs_value selected_window(emacs_env *env) { return env->funcall(env, Fselected_window, 0, (emacs_value[]){}); } -void toggle_cursor(emacs_env *env, bool visible) { - emacs_value Qvisible = visible ? Qt : Qnil; - env->funcall(env, Fset, 2, (emacs_value[]){Qcursor_type, Qvisible}); +void set_cursor_type(emacs_env *env, emacs_value QCursorType) { + env->funcall(env, Fset, 2, (emacs_value[]){Qcursor_type, QCursorType}); } void toggle_cursor_blinking(emacs_env *env, bool blinking) { - blinking = false; emacs_value Qfalse = env->make_integer(env, -1); emacs_value Qblinking = blinking ? Qt : Qfalse; env->funcall(env, Fblink_cursor_mode, 1, (emacs_value[]){Qblinking}); @@ -18,6 +18,9 @@ emacs_value Qslant; emacs_value Qreverse; emacs_value Qstrike; emacs_value Qface; +emacs_value Qbox; +emacs_value Qbar; +emacs_value Qhbar; emacs_value Qcursor_type; emacs_value Qansi_color_names_vector; @@ -59,7 +62,7 @@ void insert(emacs_env *env, emacs_value string); void goto_char(emacs_env *env, int pos); void forward_line(emacs_env *env, int n); void goto_line(emacs_env *env, int n); -void toggle_cursor(emacs_env *env, bool visible); +void set_cursor_type(emacs_env *env, emacs_value cursor_type); void toggle_cursor_blinking(emacs_env *env, bool visible); 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); diff --git a/vterm-module.c b/vterm-module.c index f4ee2b5..e971884 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -343,10 +343,39 @@ static int term_movecursor(VTermPos new, VTermPos old, int visible, return 1; } +static void term_redraw_cursor(Term *term, emacs_env *env) { + if (term->cursor.cursor_type_changed) { + term->cursor.cursor_type_changed = false; + switch (term->cursor.cursor_type) { + case VTERM_PROP_CURSOR_VISIBLE: + set_cursor_type(env, Qt); + break; + case VTERM_PROP_CURSOR_NOT_VISIBLE: + set_cursor_type(env, Qnil); + break; + case VTERM_PROP_CURSOR_BLOCK: + set_cursor_type(env, Qbox); + break; + case VTERM_PROP_CURSOR_UNDERLINE: + set_cursor_type(env, Qhbar); + break; + case VTERM_PROP_CURSOR_BAR_LEFT: + set_cursor_type(env, Qbar); + break; + default: + return; + } + } +} + static void term_redraw(Term *term, emacs_env *env) { + term_redraw_cursor(term, env); if (term->is_invalidated) { - toggle_cursor_blinking(env, term->cursor.blinking); - toggle_cursor(env, term->cursor.visible); + if (term->cursor.blinking_changed) { + toggle_cursor_blinking(env, term->cursor.blinking); + term->cursor.blinking_changed = false; + } + long bufline_before = env->extract_integer(env, buffer_line_number(env)); refresh_scrollback(term, env); refresh_screen(term, env); @@ -404,14 +433,25 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *user_data) { switch (prop) { case VTERM_PROP_CURSORVISIBLE: invalidate_terminal(term, term->cursor.row, term->cursor.row + 1); + if (val->boolean) { + term->cursor.cursor_type = VTERM_PROP_CURSOR_VISIBLE; + } else { + term->cursor.cursor_type = VTERM_PROP_CURSOR_NOT_VISIBLE; + } + term->cursor.cursor_type_changed = true; + break; + case VTERM_PROP_CURSORSHAPE: + invalidate_terminal(term, term->cursor.row, term->cursor.row + 1); + term->cursor.cursor_type = val->number; + term->cursor.cursor_type_changed = true; - term->cursor.visible = val->boolean; break; case VTERM_PROP_TITLE: term_set_title(term, val->string); break; case VTERM_PROP_CURSORBLINK: term->cursor.blinking = val->boolean; + term->cursor.blinking_changed = true; break; case VTERM_PROP_ALTSCREEN: invalidate_terminal(term, 0, term->height); @@ -606,8 +646,7 @@ static emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs, term->width = cols; term->height = rows; - term->cursor.visible = true; - term->cursor.blinking = false; + term->cursor.blinking = env->is_not_nil(env, Fblink_cursor_mode); term->title = NULL; term->is_title_changed = false; @@ -696,6 +735,9 @@ int emacs_module_init(struct emacs_runtime *ert) { Qreverse = env->make_global_ref(env, env->intern(env, ":inverse-video")); Qstrike = env->make_global_ref(env, env->intern(env, ":strike-through")); Qface = env->make_global_ref(env, env->intern(env, "font-lock-face")); + Qbox = env->make_global_ref(env, env->intern(env, "box")); + 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")); diff --git a/vterm-module.h b/vterm-module.h index 86ad81d..e9378d2 100644 --- a/vterm-module.h +++ b/vterm-module.h @@ -23,10 +23,20 @@ typedef struct ScrollbackLine { VTermScreenCell cells[]; } ScrollbackLine; +enum { + VTERM_PROP_CURSOR_BLOCK = VTERM_PROP_CURSORSHAPE_BLOCK, + VTERM_PROP_CURSOR_UNDERLINE = VTERM_PROP_CURSORSHAPE_UNDERLINE, + VTERM_PROP_CURSOR_BAR_LEFT = VTERM_PROP_CURSORSHAPE_BAR_LEFT, + VTERM_PROP_CURSOR_VISIBLE = 4, + VTERM_PROP_CURSOR_NOT_VISIBLE = 5, +}; + typedef struct Cursor { int row, col; bool blinking; - bool visible; + bool blinking_changed; + int cursor_type; + bool cursor_type_changed; } Cursor; typedef struct Term { |
