aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fürmetz <fuermetz@mailbox.org>2017-11-20 17:53:16 +0100
committerLukas Fürmetz <fuermetz@mailbox.org>2017-11-21 21:38:32 +0100
commitef64d79097af35f5d3669b792dd5ef2832e75a26 (patch)
tree643bfdc8549bdb016a49909475a6007e24f95c9d
parent8d9058143ba8d31f59fa193d483b7c6b7606324f (diff)
Implement support for hiding the cursor
-rw-r--r--elisp.c5
-rw-r--r--elisp.h3
-rw-r--r--vterm-module.c21
-rw-r--r--vterm-module.h2
4 files changed, 31 insertions, 0 deletions
diff --git a/elisp.c b/elisp.c
index c17b7e1..41c1299 100644
--- a/elisp.c
+++ b/elisp.c
@@ -106,3 +106,8 @@ void goto_char(emacs_env *env, int pos) {
emacs_value point = env->make_integer(env, pos);
env->funcall(env, Fgoto_char, 1, (emacs_value[]){point});
}
+
+void toggle_cursor(emacs_env *env, bool visible) {
+ emacs_value Qvisible = visible ? Qt : Qnil;
+ env->funcall(env, Fset, 2, (emacs_value[]){Qcursor_type, Qvisible});
+}
diff --git a/elisp.h b/elisp.h
index 2cde1a0..826a855 100644
--- a/elisp.h
+++ b/elisp.h
@@ -15,6 +15,7 @@ emacs_value Qslant;
emacs_value Qreverse;
emacs_value Qstrike;
emacs_value Qface;
+emacs_value Qcursor_type;
// Emacs functions
emacs_value Flength;
@@ -23,6 +24,7 @@ emacs_value Ferase_buffer;
emacs_value Finsert;
emacs_value Fgoto_char;
emacs_value Fput_text_property;
+emacs_value Fset;
// Utils
void bind_function(emacs_env *env, const char *name, emacs_value Sfun);
@@ -39,3 +41,4 @@ emacs_value color_to_rgb_string(emacs_env *env, VTermColor color);
void erase_buffer(emacs_env *env);
void insert(emacs_env *env, emacs_value string);
void goto_char(emacs_env *env, int pos);
+void toggle_cursor(emacs_env *env, bool visible);
diff --git a/vterm-module.c b/vterm-module.c
index 2f3c6a2..65bb1cd 100644
--- a/vterm-module.c
+++ b/vterm-module.c
@@ -39,6 +39,19 @@ static bool is_key(unsigned char *key, size_t len, char *key_description) {
memcmp(key, key_description, len) == 0);
}
+static int set_term_prop_cb(VTermProp prop, VTermValue *val, void *user_data) {
+ emacs_env *env = (emacs_env *)user_data;
+ switch (prop) {
+ case VTERM_PROP_CURSORVISIBLE:
+ toggle_cursor(env, val->boolean);
+ break;
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
static void term_redraw(struct Term *term, emacs_env *env) {
int i, j;
int rows, cols;
@@ -297,6 +310,12 @@ static emacs_value Fvterm_update(emacs_env *env, ptrdiff_t nargs,
gettimeofday(&start, NULL);
while ((len = read(term->masterfd, bytes, 4096)) > 0) {
+ VTermScreenCallbacks cb = {
+ .settermprop = set_term_prop_cb,
+ };
+ VTermScreen *screen = vterm_obtain_screen(term->vt);
+ vterm_screen_set_callbacks(screen, &cb, env);
+
vterm_input_write(term->vt, bytes, len);
term_redraw(term, env);
@@ -370,6 +389,7 @@ int emacs_module_init(struct emacs_runtime *ert) {
Qreverse = env->intern(env, ":inverse-video");
Qstrike = env->intern(env, ":strike-through");
Qface = env->intern(env, "font-lock-face");
+ Qcursor_type = env->intern(env, "cursor-type");
// Functions
Flength = env->intern(env, "length");
@@ -378,6 +398,7 @@ int emacs_module_init(struct emacs_runtime *ert) {
Finsert = env->intern(env, "insert");
Fgoto_char = env->intern(env, "goto-char");
Fput_text_property = env->intern(env, "put-text-property");
+ Fset = env->intern(env, "set");
// Exported functions
emacs_value fun;
diff --git a/vterm-module.h b/vterm-module.h
index cf67ff7..02f32af 100644
--- a/vterm-module.h
+++ b/vterm-module.h
@@ -15,6 +15,8 @@ struct Term {
static bool compare_cells(VTermScreenCell *a, VTermScreenCell *b);
static bool is_key(unsigned char *key, size_t len, char *key_description);
+static int set_term_prop_cb(VTermProp prop, VTermValue *val, void *user_data);
+
static void term_redraw(struct Term *term, emacs_env *env);
static void term_flush_output(struct Term *term);
static void term_process_key(struct Term *term, unsigned char *key, size_t len,