To: vim_dev@googlegroups.com Subject: Patch 8.1.0049 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0049 Problem: Shell cannot tell running in a terminal window. Solution: Add the VIM_TERMINAL environment variable. (Christian Brabandt) Files: runtime/doc/terminal.txt, src/os_unix.c, src/os_win32.c, src/testdir/test_terminal.vim *** ../vim-8.1.0048/runtime/doc/terminal.txt 2018-05-17 14:49:10.000000000 +0200 --- runtime/doc/terminal.txt 2018-06-12 17:43:50.152692460 +0200 *************** *** 204,210 **** ++rows={height} Use {height} for the terminal window height. If the terminal uses the full Vim height (no window above or below ! th terminal window) the command line height will be reduced as needed. ++cols={width} Use {width} for the terminal window width. If the terminal uses the full --- 204,210 ---- ++rows={height} Use {height} for the terminal window height. If the terminal uses the full Vim height (no window above or below ! the terminal window) the command line height will be reduced as needed. ++cols={width} Use {width} for the terminal window width. If the terminal uses the full *************** *** 243,249 **** You can use `CTRL-W :hide` to close the terminal window and make the buffer hidden, the job keeps running. The `:buffer` command can be used to turn the current window into a terminal window. If there are unsaved changes this ! fails, use ! to force, as usual. To have a background job run without a window, and open the window when it's done, use options like this: > --- 243,249 ---- You can use `CTRL-W :hide` to close the terminal window and make the buffer hidden, the job keeps running. The `:buffer` command can be used to turn the current window into a terminal window. If there are unsaved changes this ! fails, use ! to force, as usual. To have a background job run without a window, and open the window when it's done, use options like this: > *************** *** 376,381 **** --- 376,382 ---- COLUMNS number of columns in the terminal initially COLORS number of colors, 't_Co' (256*256*256 in the GUI) VIM_SERVERNAME v:servername + VIM_TERMINAL v:version MS-Windows ~ *** ../vim-8.1.0048/src/os_unix.c 2018-05-12 17:42:33.000000000 +0200 --- src/os_unix.c 2018-06-12 17:58:42.928059243 +0200 *************** *** 4169,4174 **** --- 4169,4175 ---- static char envbuf_Lines[20]; static char envbuf_Columns[20]; static char envbuf_Colors[20]; + static char envbuf_Version[20]; # ifdef FEAT_CLIENTSERVER static char envbuf_Servername[60]; # endif *************** *** 4189,4194 **** --- 4190,4197 ---- setenv("COLUMNS", (char *)envbuf, 1); sprintf((char *)envbuf, "%ld", colors); setenv("COLORS", (char *)envbuf, 1); + sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION)); + setenv("VIM_TERMINAL", (char *)envbuf, 1); # ifdef FEAT_CLIENTSERVER setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1); # endif *************** *** 4209,4214 **** --- 4212,4220 ---- putenv(envbuf_Columns); vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors); putenv(envbuf_Colors); + vim_snprintf(envbuf_Version, sizeof(envbuf_Version), "VIM_TERMINAL=%ld", + get_vim_var_nr(VV_VERSION)); + putenv(envbuf_Version); # ifdef FEAT_CLIENTSERVER vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername), "VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName); *** ../vim-8.1.0048/src/os_win32.c 2018-05-06 17:05:39.000000000 +0200 --- src/os_win32.c 2018-06-12 18:00:28.031513685 +0200 *************** *** 5275,5299 **** } } - # ifdef FEAT_CLIENTSERVER if (is_terminal) { char_u *servername = get_vim_var_str(VV_SEND_SERVER); ! size_t lval = STRLEN(servername); ! size_t n; ! if (ga_grow(gap, (int)(14 + lval + 2)) == OK) { for (n = 0; n < 15; n++) *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)"VIM_SERVERNAME="[n]; ! for (n = 0; n < lval; n++) *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)servername[n]; *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; } } - # endif } void --- 5275,5317 ---- } } if (is_terminal) { + # ifdef FEAT_CLIENTSERVER char_u *servername = get_vim_var_str(VV_SEND_SERVER); ! size_t servername_len = STRLEN(servername); ! # endif ! char_u *version = get_vim_var_str(VV_VERSION); ! size_t version_len = STRLEN(version); ! // size of "VIM_SERVERNAME=" and value, ! // plus "VIM_TERMINAL=" and value, ! // plus two terminating NULs ! size_t n = 0 ! # ifdef FEAT_CLIENTSERVER ! + 15 + servername_len ! # endif ! + 13 + version_len + 2; ! if (ga_grow(gap, (int)n) == OK) { + # ifdef FEAT_CLIENTSERVER for (n = 0; n < 15; n++) *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)"VIM_SERVERNAME="[n]; ! for (n = 0; n < servername_len; n++) *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)servername[n]; *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; + # endif + for (n = 0; n < 13; n++) + *((WCHAR*)gap->ga_data + gap->ga_len++) = + (WCHAR)"VIM_TERMINAL="[n]; + for (n = 0; n < version_len; n++) + *((WCHAR*)gap->ga_data + gap->ga_len++) = + (WCHAR)version[n]; + *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; } } } void *** ../vim-8.1.0048/src/testdir/test_terminal.vim 2018-06-03 18:21:57.809890160 +0200 --- src/testdir/test_terminal.vim 2018-06-12 18:01:49.195092385 +0200 *************** *** 482,499 **** if !has('clientserver') return endif let buf = Run_shell_in_terminal({}) " Wait for the shell to display a prompt call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) if has('win32') ! call term_sendkeys(buf, "echo %VIM_SERVERNAME%\r") else ! call term_sendkeys(buf, "echo $VIM_SERVERNAME\r") endif call term_wait(buf) call Stop_shell_in_terminal(buf) ! call WaitFor('getline(2) == v:servername') ! call assert_equal(v:servername, getline(2)) exe buf . 'bwipe' unlet buf --- 482,506 ---- if !has('clientserver') return endif + call s:test_environment("VIM_SERVERNAME", v:servername) + endfunc + + func Test_terminal_version() + call s:test_environment("VIM_TERMINAL", string(v:version)) + endfunc + + func s:test_environment(name, value) let buf = Run_shell_in_terminal({}) " Wait for the shell to display a prompt call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) if has('win32') ! call term_sendkeys(buf, "echo %" . a:name . "%\r") else ! call term_sendkeys(buf, "echo $" . a:name . "\r") endif call term_wait(buf) call Stop_shell_in_terminal(buf) ! call WaitForAssert({-> assert_equal(a:value, getline(2))}) exe buf . 'bwipe' unlet buf *** ../vim-8.1.0048/src/version.c 2018-06-12 17:25:32.054404315 +0200 --- src/version.c 2018-06-12 18:03:17.778632563 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 49, /**/ -- On the other hand, you have different fingers. -- Steven Wright /// 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 ///