To: vim_dev@googlegroups.com Subject: Patch 8.0.1539 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1539 Problem: No test for the popup menu positioning. Solution: Add a screendump test for the popup menu. Files: src/terminal.c, src/testdir/test_syntax.vim, src/testdir/screendump.vim, src/testdir/test_popup.vim, src/testdir/dumps/Test_popup_position_01.dump, src/testdir/dumps/Test_popup_position_02.dump, src/testdir/dumps/Test_popup_position_03.dump, runtime/doc/eval.txt *** ../vim-8.0.1538/src/terminal.c 2018-02-20 15:50:49.300325612 +0100 --- src/terminal.c 2018-02-24 19:37:15.800703648 +0100 *************** *** 1829,1835 **** switch (color->ansi_index) { case 0: return 0; ! case 1: return lookup_color( 0, fg, boldp) + 1; case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */ case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */ case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ --- 1829,1835 ---- switch (color->ansi_index) { case 0: return 0; ! case 1: return lookup_color( 0, fg, boldp) + 1; /* black */ case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */ case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */ case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ *************** *** 2872,2878 **** } /* ! * "term_dumpwrite(buf, filename, max-height, max-width)" function * * Each screen cell in full is: * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx} --- 2872,2878 ---- } /* ! * "term_dumpwrite(buf, filename, options)" function * * Each screen cell in full is: * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx} *************** *** 2899,2906 **** buf_T *buf = term_get_buf(argvars); term_T *term; char_u *fname; ! int max_height = 99999; ! int max_width = 99999; stat_T st; FILE *fd; VTermPos pos; --- 2899,2906 ---- buf_T *buf = term_get_buf(argvars); term_T *term; char_u *fname; ! int max_height = 0; ! int max_width = 0; stat_T st; FILE *fd; VTermPos pos; *************** *** 2913,2918 **** --- 2913,2935 ---- return; term = buf->b_term; + if (argvars[2].v_type != VAR_UNKNOWN) + { + dict_T *d; + + if (argvars[2].v_type != VAR_DICT) + { + EMSG(_(e_dictreq)); + return; + } + d = argvars[2].vval.v_dict; + if (d != NULL) + { + max_height = get_dict_number(d, (char_u *)"rows"); + max_width = get_dict_number(d, (char_u *)"columns"); + } + } + fname = get_tv_string_chk(&argvars[1]); if (fname == NULL) return; *************** *** 2922,2934 **** return; } - if (argvars[2].v_type != VAR_UNKNOWN) - { - max_height = get_tv_number(&argvars[2]); - if (argvars[3].v_type != VAR_UNKNOWN) - max_width = get_tv_number(&argvars[3]); - } - if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL) { EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("") : fname); --- 2939,2944 ---- *************** *** 2938,2950 **** vim_memset(&prev_cell, 0, sizeof(prev_cell)); screen = vterm_obtain_screen(term->tl_vterm); ! for (pos.row = 0; pos.row < max_height && pos.row < term->tl_rows; ! ++pos.row) { int repeat = 0; ! for (pos.col = 0; pos.col < max_width && pos.col < term->tl_cols; ! ++pos.col) { VTermScreenCell cell; int same_attr; --- 2948,2960 ---- vim_memset(&prev_cell, 0, sizeof(prev_cell)); screen = vterm_obtain_screen(term->tl_vterm); ! for (pos.row = 0; (max_height == 0 || pos.row < max_height) ! && pos.row < term->tl_rows; ++pos.row) { int repeat = 0; ! for (pos.col = 0; (max_width == 0 || pos.col < max_width) ! && pos.col < term->tl_cols; ++pos.col) { VTermScreenCell cell; int same_attr; *** ../vim-8.0.1538/src/testdir/test_syntax.vim 2018-02-24 16:51:26.783025245 +0100 --- src/testdir/test_syntax.vim 2018-02-24 19:33:19.794171619 +0100 *************** *** 5,13 **** endif source view_util.vim ! if has('terminal') ! source screendump.vim ! endif func GetSyntaxItem(pat) let c = '' --- 5,11 ---- endif source view_util.vim ! source screendump.vim func GetSyntaxItem(pat) let c = '' *************** *** 528,537 **** " Check highlighting for a small piece of C code with a screen dump. func Test_syntax_c() ! " Need to be able to run terminal Vim with 256 colors. ! " On MS-Windows the console only has 16 colors and the GUI can't run in a ! " terminal. ! if !has('terminal') || has('win32') return endif call writefile([ --- 526,532 ---- " Check highlighting for a small piece of C code with a screen dump. func Test_syntax_c() ! if !CanRunVimInTerminal() return endif call writefile([ *************** *** 561,567 **** let $COLORFGBG = '15;0' let buf = RunVimInTerminal('Xtest.c', {}) ! call VerifyScreenDump(buf, 'Test_syntax_c_01') call StopVimInTerminal(buf) let $COLORFGBG = '' --- 556,562 ---- let $COLORFGBG = '15;0' let buf = RunVimInTerminal('Xtest.c', {}) ! call VerifyScreenDump(buf, 'Test_syntax_c_01', {}) call StopVimInTerminal(buf) let $COLORFGBG = '' *** ../vim-8.0.1538/src/testdir/screendump.vim 2018-02-24 16:51:26.783025245 +0100 --- src/testdir/screendump.vim 2018-02-24 19:32:21.290534796 +0100 *************** *** 1,10 **** " Functions shared by tests making screen dumps. " Only load this script once. ! if exists('*RunVimInTerminal') finish endif source shared.vim " Run Vim with "arguments" in a new terminal window. --- 1,23 ---- " Functions shared by tests making screen dumps. " Only load this script once. ! if exists('*CanRunVimInTerminal') finish endif + " Need to be able to run terminal Vim with 256 colors. On MS-Windows the + " console only has 16 colors and the GUI can't run in a terminal. + if !has('terminal') || has('win32') + func CanRunVimInTerminal() + return 0 + endfunc + finish + endif + + func CanRunVimInTerminal() + return 1 + endfunc + source shared.vim " Run Vim with "arguments" in a new terminal window. *************** *** 41,56 **** endfunc " Verify that Vim running in terminal buffer "buf" matches the screen dump. " The file name used is "dumps/{filename}.dump". " Will wait for up to a second for the screen dump to match. ! func VerifyScreenDump(buf, filename) let reference = 'dumps/' . a:filename . '.dump' let testfile = a:filename . '.dump.failed' let i = 0 while 1 call delete(testfile) ! call term_dumpwrite(a:buf, testfile) if readfile(reference) == readfile(testfile) call delete(testfile) break --- 54,70 ---- endfunc " Verify that Vim running in terminal buffer "buf" matches the screen dump. + " "options" is passed to term_dumpwrite(). " The file name used is "dumps/{filename}.dump". " Will wait for up to a second for the screen dump to match. ! func VerifyScreenDump(buf, filename, options) let reference = 'dumps/' . a:filename . '.dump' let testfile = a:filename . '.dump.failed' let i = 0 while 1 call delete(testfile) ! call term_dumpwrite(a:buf, testfile, a:options) if readfile(reference) == readfile(testfile) call delete(testfile) break *** ../vim-8.0.1538/src/testdir/test_popup.vim 2018-02-09 15:05:58.682406498 +0100 --- src/testdir/test_popup.vim 2018-02-24 19:42:22.622790437 +0100 *************** *** 1,6 **** --- 1,7 ---- " Test for completion menu source shared.vim + source screendump.vim let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] let g:setting = '' *************** *** 743,746 **** --- 744,780 ---- \ 'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}')) endfunc + func Test_popup_position() + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ '123456789_123456789_123456789_a', + \ '123456789_123456789_123456789_b', + \ ' 123', + \ ], 'Xtest') + let buf = RunVimInTerminal('Xtest', {}) + call term_sendkeys(buf, ":vsplit\") + + " default pumwidth in left window: overlap in right window + call term_sendkeys(buf, "GA\") + call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8}) + call term_sendkeys(buf, "\u") + + " default pumwidth: fill until right of window + call term_sendkeys(buf, "\l") + call term_sendkeys(buf, "GA\") + call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8}) + + " larger pumwidth: used as minimum width + call term_sendkeys(buf, "\u") + call term_sendkeys(buf, ":set pumwidth=30\") + call term_sendkeys(buf, "GA\") + call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8}) + + call term_sendkeys(buf, "\u") + call StopVimInTerminal(buf) + call delete('Xtest') + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.0.1538/src/testdir/dumps/Test_popup_position_01.dump 2018-02-24 19:50:06.703891191 +0100 --- src/testdir/dumps/Test_popup_position_01.dump 2018-02-24 19:37:29.712616997 +0100 *************** *** 0 **** --- 1,8 ---- + |1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 + |1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 + @12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 + |6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a| @30 + |~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| | +0#4040ff13#ffffff0@30 + |~| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| | +0#4040ff13#ffffff0@30 + |~| @35||+1#0000000&|~+0#4040ff13&| @35 + |~| @35||+1#0000000&|~+0#4040ff13&| @35 *** ../vim-8.0.1538/src/testdir/dumps/Test_popup_position_02.dump 2018-02-24 19:50:06.707891167 +0100 --- src/testdir/dumps/Test_popup_position_02.dump 2018-02-24 19:40:52.003355912 +0100 *************** *** 0 **** --- 1,8 ---- + |1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 + |1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 + @12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 + |6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a| @30 + |~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 + |~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 + |~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 + |~| @35||+1#0000000&|~+0#4040ff13&| @35 *** ../vim-8.0.1538/src/testdir/dumps/Test_popup_position_03.dump 2018-02-24 19:50:06.711891141 +0100 --- src/testdir/dumps/Test_popup_position_03.dump 2018-02-24 19:42:31.826732988 +0100 *************** *** 0 **** --- 1,8 ---- + |1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 + |1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 + @12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 + |6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a| @30 + |~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @4| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_ + |~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @4| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_ + |~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 + |~| @35||+1#0000000&|~+0#4040ff13&| @35 *** ../vim-8.0.1538/runtime/doc/eval.txt 2018-02-18 22:13:06.265057933 +0100 --- runtime/doc/eval.txt 2018-02-24 19:49:26.260144013 +0100 *************** *** 2414,2420 **** Number display difference between two dumps term_dumpload({filename} [, {options}]) Number displaying a screen dump ! term_dumpwrite({buf}, {filename} [, {max-height} [, {max-width}]]) none dump terminal window contents term_getaltscreen({buf}) Number get the alternate screen flag term_getattr({attr}, {what}) Number get the value of attribute {what} --- 2419,2425 ---- Number display difference between two dumps term_dumpload({filename} [, {options}]) Number displaying a screen dump ! term_dumpwrite({buf}, {filename} [, {options}]) none dump terminal window contents term_getaltscreen({buf}) Number get the alternate screen flag term_getattr({attr}, {what}) Number get the value of attribute {what} *************** *** 8147,8159 **** {options} are not implemented yet. *term_dumpwrite()* ! term_dumpwrite({buf}, {filename} [, {max-height} [, {max-width}]]) Dump the contents of the terminal screen of {buf} in the file {filename}. This uses a format that can be used with |term_dumpread()| and |term_dumpdiff()|. If {filename} already exists an error is given. *E953* Also see |terminal-diff|. term_getaltscreen({buf}) *term_getaltscreen()* Returns 1 if the terminal of {buf} is using the alternate screen. --- 8193,8209 ---- {options} are not implemented yet. *term_dumpwrite()* ! term_dumpwrite({buf}, {filename} [, {options}]) Dump the contents of the terminal screen of {buf} in the file {filename}. This uses a format that can be used with |term_dumpread()| and |term_dumpdiff()|. If {filename} already exists an error is given. *E953* Also see |terminal-diff|. + {options} is a dictionary with these optional entries: + "rows" maximum number of rows to dump + "columns" maximum number of columns to dump + term_getaltscreen({buf}) *term_getaltscreen()* Returns 1 if the terminal of {buf} is using the alternate screen. *************** *** 8272,8278 **** line is used. When {row} is invalid an empty string is returned. ! Return a List containing a Dict for each screen cell: "chars" character(s) at the cell "fg" foreground color as #rrggbb "bg" background color as #rrggbb --- 8322,8328 ---- line is used. When {row} is invalid an empty string is returned. ! Return a List containing a Dict for each screen cell: "chars" character(s) at the cell "fg" foreground color as #rrggbb "bg" background color as #rrggbb *************** *** 8289,8297 **** --- 8339,8356 ---- means the character CTRL-X. {only available when compiled with the |+terminal| feature} + term_setsize({buf}, {expr}) *term_setsize()* + Not implemented yet. + {only available when compiled with the |+terminal| feature} + term_start({cmd}, {options}) *term_start()* Open a terminal window and run {cmd} in it. + {cmd} can be a string or a List, like with |job_start()|. The + string "NONE" can be used to open a terminal window without + starting a job, the pty of the terminal can be used by a + command like gdb. + Returns the buffer number of the terminal window. If {cmd} cannot be executed the window does open and shows an error message. *** ../vim-8.0.1538/src/version.c 2018-02-24 18:59:18.890876335 +0100 --- src/version.c 2018-02-24 19:17:16.740106624 +0100 *************** *** 780,781 **** --- 780,783 ---- { /* Add new patch number below this line */ + /**/ + 1539, /**/ -- Any sufficiently advanced technology is indistinguishable from magic. Arthur C. Clarke Any sufficiently advanced bug is indistinguishable from a feature. Rich Kulawiec /// 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 ///