Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 1 | " Functions about view shared by several tests |
| 2 | |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame^] | 3 | " Only load this script once. |
| 4 | if exists('*ScreenLines') |
| 5 | finish |
| 6 | endif |
| 7 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 8 | " ScreenLines(lnum, width) or |
| 9 | " ScreenLines([start, end], width) |
| 10 | function! ScreenLines(lnum, width) abort |
| 11 | redraw! |
| 12 | if type(a:lnum) == v:t_list |
| 13 | let start = a:lnum[0] |
| 14 | let end = a:lnum[1] |
| 15 | else |
| 16 | let start = a:lnum |
| 17 | let end = a:lnum |
| 18 | endif |
| 19 | let lines = [] |
| 20 | for l in range(start, end) |
| 21 | let lines += [join(map(range(1, a:width), 'nr2char(screenchar(l, v:val))'), '')] |
| 22 | endfor |
| 23 | return lines |
| 24 | endfunction |
| 25 | |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame^] | 26 | function! ScreenAttrs(lnum, width) abort |
| 27 | redraw! |
| 28 | if type(a:lnum) == v:t_list |
| 29 | let start = a:lnum[0] |
| 30 | let end = a:lnum[1] |
| 31 | else |
| 32 | let start = a:lnum |
| 33 | let end = a:lnum |
| 34 | endif |
| 35 | let attrs = [] |
| 36 | for l in range(start, end) |
| 37 | let attrs += [map(range(1, a:width), 'screenattr(l, v:val)')] |
| 38 | endfor |
| 39 | return attrs |
| 40 | endfunction |
| 41 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 42 | function! NewWindow(height, width) abort |
| 43 | exe a:height . 'new' |
| 44 | exe a:width . 'vsp' |
| 45 | redraw! |
| 46 | endfunction |
| 47 | |
| 48 | function! CloseWindow() abort |
| 49 | bw! |
| 50 | redraw! |
| 51 | endfunction |