comparison runtime/doc/terminal.txt @ 13304:013c44d9dc09 v8.0.1526

patch 8.0.1526: no test using a screen dump yet commit https://github.com/vim/vim/commit/da65058a9c4774dc534c7ae98d24c58b5db669fa Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 20 15:51:40 2018 +0100 patch 8.0.1526: no test using a screen dump yet Problem: No test using a screen dump yet. Solution: Add a test for C syntax highlighting. Add helper functions.
author Christian Brabandt <cb@256bit.org>
date Tue, 20 Feb 2018 16:00:06 +0100
parents 371ceeebbdaa
children 1ffba37fd222
comparison
equal deleted inserted replaced
13303:b97157007be1 13304:013c44d9dc09
1 *terminal.txt* For Vim version 8.0. Last change: 2018 Jan 28 1 *terminal.txt* For Vim version 8.0. Last change: 2018 Feb 20
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
12 The terminal feature is optional, use this to check if your Vim has it: > 12 The terminal feature is optional, use this to check if your Vim has it: >
13 echo has('terminal') 13 echo has('terminal')
14 If the result is "1" you have it. 14 If the result is "1" you have it.
15 15
16 16
17 1. Basic use |terminal-use| 17 1. Basic use |terminal-use|
18 Typing |terminal-typing| 18 Typing |terminal-typing|
19 Size and color |terminal-size-color| 19 Size and color |terminal-size-color|
20 Syntax |:terminal| 20 Syntax |:terminal|
21 Resizing |terminal-resizing| 21 Resizing |terminal-resizing|
22 Terminal Modes |Terminal-mode| 22 Terminal Modes |Terminal-mode|
23 Cursor style |terminal-cursor-style| 23 Cursor style |terminal-cursor-style|
24 Special keys |terminal-special-keys| 24 Special keys |terminal-special-keys|
25 Unix |terminal-unix| 25 Unix |terminal-unix|
26 MS-Windows |terminal-ms-windows| 26 MS-Windows |terminal-ms-windows|
27 2. Remote testing |terminal-testing| 27 2. Remote testing |terminal-testing|
28 3. Debugging |terminal-debug| 28 3. Diffing screen dumps |terminal-diff|
29 Starting |termdebug-starting| 29 Writing a screen dump test for Vim |terminal-dumptest|
30 Example session |termdebug-example| 30 Creating a screen dump |terminal-screendump|
31 Stepping through code |termdebug-stepping| 31 Comparing screen dumps |terminal-diffscreendump|
32 Inspecting variables |termdebug-variables| 32 4. Debugging |terminal-debug|
33 Other commands |termdebug-commands| 33 Starting |termdebug-starting|
34 Communication |termdebug-communication| 34 Example session |termdebug-example|
35 Customizing |termdebug-customizing| 35 Stepping through code |termdebug-stepping|
36 Inspecting variables |termdebug-variables|
37 Other commands |termdebug-commands|
38 Communication |termdebug-communication|
39 Customizing |termdebug-customizing|
36 40
37 {Vi does not have any of these commands} 41 {Vi does not have any of these commands}
38 {only available when compiled with the |+terminal| feature} 42 {only available when compiled with the |+terminal| feature}
39 43
40 The terminal feature requires the |+multi_byte|, |+job| and |+channel| features. 44 The terminal feature requires the |+multi_byte|, |+job| and |+channel| features.
358 term_wait() wait for screen to be updated 362 term_wait() wait for screen to be updated
359 term_scrape() inspect terminal screen 363 term_scrape() inspect terminal screen
360 364
361 365
362 ============================================================================== 366 ==============================================================================
363 3. Debugging *terminal-debug* 367 3. Diffing screen dumps *terminal-diff*
368
369 In some cases it can be bothersome to test that Vim displays the right
370 characters on the screen. E.g. with syntax highlighting. To make this
371 simpler it is possible to take a screen dump of a terminal and compare it to
372 an expected screen dump.
373
374 Vim uses the window size, text, color and other attributes as displayed. The
375 Vim screen size, font and other properties do not matter. Therefore this
376 mechanism is portable across systems. A convential screenshot would reflect
377 all differences, including font size and family.
378
379
380 Writing a screen dump test for Vim ~
381 *terminal-dumptest*
382 For an example see the Test_syntax_c() function in
383 src/testdir/test_syntax.vim. The main parts are:
384 - Write a file you want to test with. This is useful for testing syntax
385 highlighting. You can also start Vim with en empty buffer.
386 - Run Vim in a terminal with a specific size. The default is 20 lines of 75
387 characters. This makes sure the dump is always this size. The function
388 RunVimInTerminal() takes care of this. Pass it the arguments for the Vim
389 command.
390 - Send any commands to Vim using term_sendkeys(). For example: >
391 call term_sendkeys(buf, ":echo &lines &columns\<CR>")
392 - Check that the screen is now in the expected state, using
393 VerifyScreenDump(). This expects the reference screen dump to be in the
394 src/testdir/dumps/ directory. Pass the name without ".dump". It is
395 recommended to use the name of the test function and a sequence number, so
396 that we know what test is using the file.
397 - Repeat sending commands and checking the state.
398 - Finally stop Vim by calling StopVimInTerminal().
399
400 The first time you do this you won't have a screen dump yet. Create an empty
401 file for now, e.g.: >
402 touch src/testdir/dumps/Test_function_name_01.dump
403
404 The test will then fail, giving you the command to compare the reference dump
405 and the failed dump, e.g.: >
406 call term_dumpdiff("Test_func.dump.failed", "dumps/Test_func.dump")
407
408 Use this command in Vim, with the current directory set to src/testdir.
409 Once you are satisfied with the test, move the failed dump in place of the
410 reference: >
411 :!mv Test_func.dump.failed dumps/Test_func.dump
412
413
414 Creating a screen dump ~
415 *terminal-screendump*
416
417 To create the screen dump, run Vim (or any other program) in a terminal and
418 make it show the desired state. Then use the term_dumpwrite() function to
419 create a screen dump file. For example: >
420 :call term_dumpwrite(77, "mysyntax.dump")
421
422 Here "77" is the buffer number of the terminal. Use `:ls!` to see it.
423
424 You can view the screen dump with term_dumpload(): >
425 :call term_dumpload("mysyntax.dump")
426
427 To verify that Vim still shows exactly the same screen, run Vim again with
428 exactly the same way to show the desired state. Then create a screen dump
429 again, using a different file name: >
430 :call term_dumpwrite(88, "test.dump")
431
432 To assert that the files are exactly the same use assert_equalfile(): >
433 call assert_equalfile("mysyntax.dump", "test.dump")
434
435 If there are differences then v:errors will contain the error message.
436
437
438 Comparing screen dumps ~
439 *terminal-diffscreendump*
440
441 assert_equalfile() does not make it easy to see what is different.
442 To spot the problem use term_dumpdiff(): >
443 call term_dumpdiff("mysyntax.dump", "test.dump")
444
445 This will open a window consisting of three parts:
446 1. The contents of the first dump
447 2. The difference between the first and second dump
448 3. The contents of the second dump
449
450 You can usually see what differs in the second part. Use the 'ruler' to
451 relate it to the postion in the first or second dump.
452
453 Alternatively, press "s" to swap the first and second dump. Do this everal
454 times so that you can spot the difference in the context of the text.
455
456 ==============================================================================
457 4. Debugging *terminal-debug*
364 458
365 The Terminal debugging plugin can be used to debug a program with gdb and view 459 The Terminal debugging plugin can be used to debug a program with gdb and view
366 the source code in a Vim window. Since this is completely contained inside 460 the source code in a Vim window. Since this is completely contained inside
367 Vim this also works remotely over an ssh connection. 461 Vim this also works remotely over an ssh connection.
368 462
473 567
474 :Break set a breakpoint at the current line; a sign will be displayed 568 :Break set a breakpoint at the current line; a sign will be displayed
475 :Delete delete a breakpoint at the current line 569 :Delete delete a breakpoint at the current line
476 570
477 :Step execute the gdb "step" command 571 :Step execute the gdb "step" command
478 :Over execute the gdb "next" command (:Next is a Vim command) 572 :Over execute the gdb "next" command (:Next is a Vim command)
479 :Finish execute the gdb "finish" command 573 :Finish execute the gdb "finish" command
480 :Continue execute the gdb "continue" command 574 :Continue execute the gdb "continue" command
481 :Stop interrupt the program 575 :Stop interrupt the program
482 576
483 If 'mouse' is set the plugin adds a window toolbar with these entries: 577 If 'mouse' is set the plugin adds a window toolbar with these entries: