Mercurial > vim
changeset 12800:8dfeed7e07e7 v8.0.1277
patch 8.0.1277: terminal window CR-NL conversions may cause problems
commit https://github.com/vim/vim/commit/26d205dcd886b48713f22cbdbf2a8e55400083dc
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 9 17:33:11 2017 +0100
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Problem: Terminal window CR-NL conversions may cause problems.
Solution: Avoid most conversions, only fetch the current backspace key value
from the tty. (mostly by Ozaki Kiichi, closes #2278)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 09 Nov 2017 17:45:05 +0100 |
parents | a27dc6d11c0a |
children | b4521872e498 |
files | src/terminal.c src/version.c |
diffstat | 2 files changed, 28 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/src/terminal.c +++ b/src/terminal.c @@ -181,11 +181,9 @@ static int create_pty_only(term_T *term, static void term_report_winsize(term_T *term, int rows, int cols); static void term_free_vterm(term_T *term); -/* The characters that we know (or assume) that the terminal expects for the - * backspace and enter keys. */ +/* The character that we know (or assume) that the terminal expects for the + * backspace key. */ static int term_backspace_char = BS; -static int term_enter_char = CAR; -static int term_nl_does_cr = FALSE; /************************************** @@ -651,30 +649,8 @@ free_terminal(buf_T *buf) term_write_job_output(term_T *term, char_u *msg, size_t len) { VTerm *vterm = term->tl_vterm; - char_u *p; - size_t done; - size_t len_now; - - if (term_nl_does_cr) - vterm_input_write(vterm, (char *)msg, len); - else - /* need to convert NL to CR-NL */ - for (done = 0; done < len; done += len_now) - { - for (p = msg + done; p < msg + len; ) - { - if (*p == NL) - break; - p += utf_ptr2len_len(p, (int)(len - (p - msg))); - } - len_now = p - msg - done; - vterm_input_write(vterm, (char *)msg + done, len_now); - if (p < msg + len && *p == NL) - { - vterm_input_write(vterm, "\r\n", 2); - ++len_now; - } - } + + vterm_input_write(vterm, (char *)msg, len); /* this invokes the damage callbacks */ vterm_screen_flush_damage(vterm_obtain_screen(vterm)); @@ -760,7 +736,8 @@ term_convert_key(term_T *term, int c, ch switch (c) { - case CAR: c = term_enter_char; break; + /* don't use VTERM_KEY_ENTER, it may do an unwanted conversion */ + /* don't use VTERM_KEY_BACKSPACE, it always * becomes 0x7f DEL */ case K_BS: c = term_backspace_char; break; @@ -1534,7 +1511,8 @@ terminal_loop(int blocking) int termkey = 0; int ret; #ifdef UNIX - int tty_fd = curbuf->b_term->tl_job->jv_channel->ch_part[get_tty_part(curbuf->b_term)].ch_fd; + int tty_fd = curbuf->b_term->tl_job->jv_channel + ->ch_part[get_tty_part(curbuf->b_term)].ch_fd; #endif /* Remember the terminal we are sending keys to. However, the terminal @@ -1557,30 +1535,11 @@ terminal_loop(int blocking) break; update_cursor(curbuf->b_term, FALSE); -#ifdef UNIX - /* - * The shell or another program may change the tty settings. Getting - * them for every typed character is a bit of overhead, but it's needed - * for the first CR typed, e.g. when Vim starts in a shell. - */ - if (isatty(tty_fd)) - { - ttyinfo_T info; - - /* Get the current backspace and enter characters of the pty. */ - if (get_tty_info(tty_fd, &info) == OK) - { - term_backspace_char = info.backspace; - term_enter_char = info.enter; - term_nl_does_cr = info.nl_does_cr; - } - } -#endif - c = term_vgetc(); if (!term_use_loop()) { - /* job finished while waiting for a character */ + /* Job finished while waiting for a character. Push back the + * received character. */ if (c != K_IGNORE) vungetc(c); break; @@ -1588,6 +1547,22 @@ terminal_loop(int blocking) if (c == K_IGNORE) continue; +#ifdef UNIX + /* + * The shell or another program may change the tty settings. Getting + * them for every typed character is a bit of overhead, but it's needed + * for the first character typed, e.g. when Vim starts in a shell. + */ + if (isatty(tty_fd)) + { + ttyinfo_T info; + + /* Get the current backspace character of the pty. */ + if (get_tty_info(tty_fd, &info) == OK) + term_backspace_char = info.backspace; + } +#endif + #ifdef WIN3264 /* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT. * Use CTRL-BREAK to kill the job. */