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 | 2912abb | 2019-03-29 14:16:42 +0100 | [diff] [blame^] | 8 | " Get text on the screen, without composing characters. |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 9 | " ScreenLines(lnum, width) or |
| 10 | " ScreenLines([start, end], width) |
| 11 | function! ScreenLines(lnum, width) abort |
| 12 | redraw! |
| 13 | if type(a:lnum) == v:t_list |
| 14 | let start = a:lnum[0] |
| 15 | let end = a:lnum[1] |
| 16 | else |
| 17 | let start = a:lnum |
| 18 | let end = a:lnum |
| 19 | endif |
| 20 | let lines = [] |
| 21 | for l in range(start, end) |
| 22 | let lines += [join(map(range(1, a:width), 'nr2char(screenchar(l, v:val))'), '')] |
| 23 | endfor |
| 24 | return lines |
| 25 | endfunction |
| 26 | |
Bram Moolenaar | 2912abb | 2019-03-29 14:16:42 +0100 | [diff] [blame^] | 27 | " Get text on the screen, including composing characters. |
| 28 | " ScreenLines(lnum, width) or |
| 29 | " ScreenLines([start, end], width) |
| 30 | function! ScreenLinesUtf8(lnum, width) abort |
| 31 | redraw! |
| 32 | if type(a:lnum) == v:t_list |
| 33 | let start = a:lnum[0] |
| 34 | let end = a:lnum[1] |
| 35 | else |
| 36 | let start = a:lnum |
| 37 | let end = a:lnum |
| 38 | endif |
| 39 | let lines = [] |
| 40 | for l in range(start, end) |
| 41 | let lines += [join(map(range(1, a:width), 'screenstring(l, v:val)'), '')] |
| 42 | endfor |
| 43 | return lines |
| 44 | endfunction |
| 45 | |
Bram Moolenaar | 0aa398f | 2017-09-30 21:23:55 +0200 | [diff] [blame] | 46 | function! ScreenAttrs(lnum, width) abort |
| 47 | redraw! |
| 48 | if type(a:lnum) == v:t_list |
| 49 | let start = a:lnum[0] |
| 50 | let end = a:lnum[1] |
| 51 | else |
| 52 | let start = a:lnum |
| 53 | let end = a:lnum |
| 54 | endif |
| 55 | let attrs = [] |
| 56 | for l in range(start, end) |
| 57 | let attrs += [map(range(1, a:width), 'screenattr(l, v:val)')] |
| 58 | endfor |
| 59 | return attrs |
| 60 | endfunction |
| 61 | |
Bram Moolenaar | 544d3bc | 2017-02-05 21:14:50 +0100 | [diff] [blame] | 62 | function! NewWindow(height, width) abort |
| 63 | exe a:height . 'new' |
| 64 | exe a:width . 'vsp' |
| 65 | redraw! |
| 66 | endfunction |
| 67 | |
| 68 | function! CloseWindow() abort |
| 69 | bw! |
| 70 | redraw! |
| 71 | endfunction |