diff options
| author | jixiufeng <jixiufeng@luojilab.com> | 2019-05-18 00:05:35 +0800 |
|---|---|---|
| committer | jixiufeng <jixiufeng@luojilab.com> | 2019-05-18 00:05:35 +0800 |
| commit | dce7666b83d8c3a8d9ef9da532b3ac85590a926d (patch) | |
| tree | 28375d95fe1c87bf7544934e0b36586e486bccb4 | |
| parent | 74b8e5cb2d1c6798c42e56ae444e5e96c629f2c5 (diff) | |
support set cursor type
| -rw-r--r-- | elisp.c | 5 | ||||
| -rw-r--r-- | elisp.h | 5 | ||||
| -rw-r--r-- | vterm-module.c | 43 | ||||
| -rw-r--r-- | vterm-module.h | 11 |
4 files changed, 56 insertions, 8 deletions
@@ -98,9 +98,8 @@ 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) { @@ -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 61de618..e971884 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -343,14 +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) { if (term->cursor.blinking_changed) { toggle_cursor_blinking(env, term->cursor.blinking); term->cursor.blinking_changed = false; } - toggle_cursor(env, term->cursor.visible); long bufline_before = env->extract_integer(env, buffer_line_number(env)); refresh_scrollback(term, env); refresh_screen(term, env); @@ -408,8 +433,18 @@ 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); @@ -611,7 +646,6 @@ static emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs, term->width = cols; term->height = rows; - term->cursor.visible = true; term->cursor.blinking = env->is_not_nil(env, Fblink_cursor_mode); term->title = NULL; term->is_title_changed = false; @@ -701,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 d3d0a08..e9378d2 100644 --- a/vterm-module.h +++ b/vterm-module.h @@ -23,11 +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 blinking_changed; - bool visible; + int cursor_type; + bool cursor_type_changed; } Cursor; typedef struct Term { |
