Mercurial > vim
diff src/terminal.c @ 13132:fe0cec169589 v8.0.1440
patch 8.0.1440: terminal window: some vterm responses are delayed
commit https://github.com/vim/vim/commit/b50773c6df0bc2c9c2ab1afecc78083abc606de0
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 30 22:31:19 2018 +0100
patch 8.0.1440: terminal window: some vterm responses are delayed
Problem: Terminal window: some vterm responses are delayed.
Solution: After writing input. check if there is output to read. (Ozaki
Kiichi, closes #2594)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 30 Jan 2018 22:45:05 +0100 |
parents | 149347fda678 |
children | 53f0c469dfc6 |
line wrap: on
line diff
--- a/src/terminal.c +++ b/src/terminal.c @@ -650,15 +650,50 @@ free_terminal(buf_T *buf) } /* + * Get the part that is connected to the tty. Normally this is PART_IN, but + * when writing buffer lines to the job it can be another. This makes it + * possible to do "1,5term vim -". + */ + static ch_part_T +get_tty_part(term_T *term) +{ +#ifdef UNIX + ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR}; + int i; + + for (i = 0; i < 3; ++i) + { + int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd; + + if (isatty(fd)) + return parts[i]; + } +#endif + return PART_IN; +} + +/* * Write job output "msg[len]" to the vterm. */ static void term_write_job_output(term_T *term, char_u *msg, size_t len) { VTerm *vterm = term->tl_vterm; + size_t prevlen = vterm_output_get_buffer_current(vterm); vterm_input_write(vterm, (char *)msg, len); + /* flush vterm buffer when vterm responded to control sequence */ + if (prevlen != vterm_output_get_buffer_current(vterm)) + { + char buf[KEY_BUF_LEN]; + size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN); + + if (curlen > 0) + channel_send(term->tl_job->jv_channel, get_tty_part(term), + (char_u *)buf, (int)curlen, NULL); + } + /* this invokes the damage callbacks */ vterm_screen_flush_damage(vterm_obtain_screen(vterm)); } @@ -1239,29 +1274,6 @@ term_vgetc() } /* - * Get the part that is connected to the tty. Normally this is PART_IN, but - * when writing buffer lines to the job it can be another. This makes it - * possible to do "1,5term vim -". - */ - static ch_part_T -get_tty_part(term_T *term) -{ -#ifdef UNIX - ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR}; - int i; - - for (i = 0; i < 3; ++i) - { - int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd; - - if (isatty(fd)) - return parts[i]; - } -#endif - return PART_IN; -} - -/* * Send keys to terminal. * Return FAIL when the key needs to be handled in Normal mode. * Return OK when the key was dropped or sent to the terminal.