To: vim_dev@googlegroups.com Subject: Patch 8.0.1786 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1786 Problem: No test for 'termwinkey'. Solution: Add a test. Make feedkeys() handle terminal_loop() returning before characters are consumed. Files: src/testdir/test_terminal.vim, src/terminal.c, src/evalfunc.c, src/ex_docmd.c, src/getchar.c, src/keymap.h *** ../vim-8.0.1785/src/testdir/test_terminal.vim 2018-04-30 18:03:06.256235076 +0200 --- src/testdir/test_terminal.vim 2018-05-01 18:38:41.011586267 +0200 *************** *** 1471,1473 **** --- 1471,1489 ---- set termwinsize= endfunc + + func Test_terminal_termwinkey() + call assert_equal(1, winnr('$')) + let thiswin = win_getid() + + let buf = Run_shell_in_terminal({}) + let termwin = bufwinid(buf) + set termwinkey= + call feedkeys("\w", 'tx') + call assert_equal(thiswin, win_getid()) + call feedkeys("\w", 'tx') + + let job = term_getjob(buf) + call feedkeys("\\", 'tx') + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + endfunc *** ../vim-8.0.1785/src/terminal.c 2018-05-01 15:47:30.300975408 +0200 --- src/terminal.c 2018-05-01 18:40:32.706901068 +0200 *************** *** 42,48 **** * redirection. Probably in call to channel_set_pipes(). * - Win32: Redirecting output does not work, Test_terminal_redir_file() * is disabled. - * - Add test for 'termwinkey'. * - When starting terminal window with shell in terminal, then using :gui to * switch to GUI, shell stops working. Scrollback seems wrong, command * running in shell is still running. --- 42,47 ---- *************** *** 1690,1695 **** --- 1689,1695 ---- return FAIL; case K_IGNORE: + case K_CANCEL: // used for :normal when running out of chars return FAIL; case K_LEFTDRAG: *************** *** 1826,1834 **** } } - #if defined(FEAT_GUI) || defined(PROTO) /* ! * Return TRUE when the cursor of the terminal should be displayed. */ int terminal_is_active() --- 1826,1834 ---- } } /* ! * Return TRUE when waiting for a character in the terminal, the cursor of the ! * terminal should be displayed. */ int terminal_is_active() *************** *** 1836,1841 **** --- 1836,1842 ---- return in_terminal_loop != NULL; } + #if defined(FEAT_GUI) || defined(PROTO) cursorentry_T * term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) { *** ../vim-8.0.1785/src/evalfunc.c 2018-04-28 16:56:20.788322741 +0200 --- src/evalfunc.c 2018-05-01 18:06:48.186981473 +0200 *************** *** 3311,3328 **** /* Avoid a 1 second delay when the keys start Insert mode. */ msg_scroll = FALSE; ! #ifdef FEAT_TERMINAL ! if (term_use_loop()) ! terminal_loop(FALSE); ! else ! #endif ! { ! if (!dangerous) ! ++ex_normal_busy; ! exec_normal(TRUE); ! if (!dangerous) ! --ex_normal_busy; ! } msg_scroll |= save_msg_scroll; } } --- 3311,3322 ---- /* Avoid a 1 second delay when the keys start Insert mode. */ msg_scroll = FALSE; ! if (!dangerous) ! ++ex_normal_busy; ! exec_normal(TRUE); ! if (!dangerous) ! --ex_normal_busy; ! msg_scroll |= save_msg_scroll; } } *** ../vim-8.0.1785/src/ex_docmd.c 2018-04-29 12:22:49.163522596 +0200 --- src/ex_docmd.c 2018-05-01 18:07:06.066869329 +0200 *************** *** 10340,10346 **** && typebuf.tb_len > 0)) && !got_int) { update_topline_cursor(); ! normal_cmd(&oa, TRUE); /* execute a Normal mode cmd */ } } --- 10340,10360 ---- && typebuf.tb_len > 0)) && !got_int) { update_topline_cursor(); ! #ifdef FEAT_TERMINAL ! if (term_use_loop() ! && oa.op_type == OP_NOP && oa.regname == NUL ! && !VIsual_active) ! { ! /* If terminal_loop() returns OK we got a key that is handled ! * in Normal model. With FAIL we first need to position the ! * cursor and the screen needs to be redrawn. */ ! if (terminal_loop(TRUE) == OK) ! normal_cmd(&oa, TRUE); ! } ! else ! #endif ! /* execute a Normal mode cmd */ ! normal_cmd(&oa, TRUE); } } *** ../vim-8.0.1785/src/getchar.c 2018-04-24 15:19:00.503068778 +0200 --- src/getchar.c 2018-05-01 18:40:20.714974708 +0200 *************** *** 2059,2065 **** c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L); /* * If inchar() returns TRUE (script file was active) or we ! * are inside a mapping, get out of insert mode. * Otherwise we behave like having gotten a CTRL-C. * As a result typing CTRL-C in insert mode will * really insert a CTRL-C. --- 2059,2065 ---- c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L); /* * If inchar() returns TRUE (script file was active) or we ! * are inside a mapping, get out of Insert mode. * Otherwise we behave like having gotten a CTRL-C. * As a result typing CTRL-C in insert mode will * really insert a CTRL-C. *************** *** 2755,2760 **** --- 2755,2764 ---- * cmdline window. */ if (p_im && (State & INSERT)) c = Ctrl_L; + #ifdef FEAT_TERMINAL + else if (terminal_is_active()) + c = K_CANCEL; + #endif else if ((State & CMDLINE) #ifdef FEAT_CMDWIN || (cmdwin_type > 0 && tc == ESC) *************** *** 2898,2905 **** } /* for (;;) */ } /* if (!character from stuffbuf) */ ! /* if advance is FALSE don't loop on NULs */ ! } while (c < 0 || (advance && c == NUL)); /* * The "INSERT" message is taken care of here: --- 2902,2909 ---- } /* for (;;) */ } /* if (!character from stuffbuf) */ ! /* if advance is FALSE don't loop on NULs */ ! } while ((c < 0 && c != K_CANCEL) || (advance && c == NUL)); /* * The "INSERT" message is taken care of here: *** ../vim-8.0.1785/src/keymap.h 2017-11-18 18:51:08.117770819 +0100 --- src/keymap.h 2018-05-01 18:40:08.967046833 +0200 *************** *** 270,275 **** --- 270,276 ---- , KE_FOCUSGAINED = 98 /* focus gained */ , KE_FOCUSLOST = 99 /* focus lost */ , KE_MOUSEMOVE = 100 /* mouse moved with no button down */ + , KE_CANCEL = 101 /* return from vgetc() */ }; /* *************** *** 455,460 **** --- 456,462 ---- #define K_IGNORE TERMCAP2KEY(KS_EXTRA, KE_IGNORE) #define K_NOP TERMCAP2KEY(KS_EXTRA, KE_NOP) + #define K_CANCEL TERMCAP2KEY(KS_EXTRA, KE_CANCEL) #define K_MOUSEDOWN TERMCAP2KEY(KS_EXTRA, KE_MOUSEDOWN) #define K_MOUSEUP TERMCAP2KEY(KS_EXTRA, KE_MOUSEUP) *** ../vim-8.0.1785/src/version.c 2018-05-01 17:30:37.332260582 +0200 --- src/version.c 2018-05-01 18:02:31.416586676 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1786, /**/ -- Q: How does a UNIX Guru do Sex ? A: unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///