diff options
| author | jixiuf <jixiuf@qq.com> | 2020-03-21 13:42:47 +0800 |
|---|---|---|
| committer | jixiuf <jixiuf@qq.com> | 2020-03-27 22:47:55 +0800 |
| commit | 996c535b9cc6aa70c3595413582d97abfab16edd (patch) | |
| tree | b73c0d944401cba5efb908eb1de1c4a6c2f1bf2f /vterm-module.c | |
| parent | 7a247906c17f97f6edad6c478da0c34307db2b80 (diff) | |
reimplements vterm--get-prompt-point with text property and bind vterm-previous-prompt and vterm-next-prompt.
Diffstat (limited to 'vterm-module.c')
| -rw-r--r-- | vterm-module.c | 73 |
1 files changed, 46 insertions, 27 deletions
diff --git a/vterm-module.c b/vterm-module.c index a635427..ae3d330 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -216,7 +216,22 @@ static bool is_eol(Term *term, int end_col, int row, int col) { } return 1; } - +static int is_end_of_prompt(Term *term, int end_col, int row, int col) { + LineInfo *info = get_lineinfo(term, row); + if (info == NULL) { + return 0; + } + if (info->prompt_col < 0) { + return 0; + } + if (info->prompt_col == col) { + return 1; + } + if (is_eol(term, end_col, row, col) && info->prompt_col >= col) { + return 1; + } + return 0; +} static size_t get_col_offset(Term *term, int row, int end_col) { int col = 0; size_t offset = 0; @@ -255,12 +270,23 @@ static void refresh_lines(Term *term, emacs_env *env, int start_row, VTermScreenCell lastCell; fetch_cell(term, start_row, 0, &lastCell); - int offset = 0; for (i = start_row; i < end_row; i++) { int newline = 0; + int isprompt = 0; for (j = 0; j < end_col; j++) { fetch_cell(term, i, j, &cell); + if (isprompt && length > 0) { + emacs_value text = render_text(env, term, buffer, length, &lastCell); + insert(env, render_prompt(env, text)); + length = 0; + } + + isprompt = is_end_of_prompt(term, end_col, i, j); + if (isprompt && length > 0) { + insert(env, render_text(env, term, buffer, length, &lastCell)); + length = 0; + } if (!compare_cells(&cell, &lastCell)) { emacs_value text = render_text(env, term, buffer, length, &lastCell); @@ -290,10 +316,15 @@ static void refresh_lines(Term *term, emacs_env *env, int start_row, if (cell.width > 1) { int w = cell.width - 1; - offset += w; j = j + w; } } + if (isprompt && length > 0) { + emacs_value text = render_text(env, term, buffer, length, &lastCell); + insert(env, render_prompt(env, text)); + length = 0; + isprompt = 0; + } if (!newline) { emacs_value text = render_text(env, term, buffer, length, &lastCell); @@ -666,6 +697,17 @@ static emacs_value render_text(emacs_env *env, Term *term, char *buffer, return text; } +static emacs_value render_prompt(emacs_env *env, emacs_value text) { + + emacs_value properties; + + properties = + list(env, (emacs_value[]){Qvterm_prompt, Qt, Qrear_nonsticky, Qt}, 4); + + add_text_properties(env, text, properties); + + return text; +} static emacs_value render_fake_newline(emacs_env *env, Term *term) { @@ -1104,27 +1146,6 @@ emacs_value Fvterm_get_icrnl(emacs_env *env, ptrdiff_t nargs, return Qnil; } -emacs_value Fvterm_get_prompt_point(emacs_env *env, ptrdiff_t nargs, - emacs_value args[], void *data) { - Term *term = env->get_user_ptr(env, args[0]); - int linenum = env->extract_integer(env, args[1]); - if (linenum >= term->linenum) { - linenum = term->linenum; - } - for (int l = linenum; l >= 1; l--) { - int cur_row = linenr_to_row(term, l); - LineInfo *info = get_lineinfo(term, cur_row); - if (info != NULL && info->prompt_col >= 0) { - goto_line(env, l); - size_t offset = get_col_offset(term, cur_row, info->prompt_col); - forward_char(env, env->make_integer(env, info->prompt_col - offset)); - - return point(env); - } - } - return Qnil; -} - emacs_value Fvterm_reset_cursor_point(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data) { Term *term = env->get_user_ptr(env, args[0]); @@ -1158,6 +1179,7 @@ int emacs_module_init(struct emacs_runtime *ert) { env->make_global_ref(env, env->intern(env, "vterm-line-wrap")); Qrear_nonsticky = env->make_global_ref(env, env->intern(env, "rear-nonsticky")); + Qvterm_prompt = env->make_global_ref(env, env->intern(env, "vterm-prompt")); Qface = env->make_global_ref(env, env->intern(env, "font-lock-face")); Qbox = env->make_global_ref(env, env->intern(env, "box")); @@ -1236,9 +1258,6 @@ int emacs_module_init(struct emacs_runtime *ert) { fun = env->make_function(env, 2, 2, Fvterm_get_pwd, "Get the working directory of at line n.", NULL); bind_function(env, "vterm--get-pwd-raw", fun); - fun = env->make_function(env, 2, 2, Fvterm_get_prompt_point, - "Get the end postion of current prompt.", NULL); - bind_function(env, "vterm--get-prompt-point-internal", fun); fun = env->make_function(env, 1, 1, Fvterm_reset_cursor_point, "Reset cursor postion.", NULL); bind_function(env, "vterm--reset-point", fun); |
