blob: 34b4519bcfa5d5b1f2b63fb6560490aeeb51387a [file] [log] [blame]
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01001" Functions about view shared by several tests
2
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02003" Only load this script once.
4if exists('*ScreenLines')
5 finish
6endif
7
Bram Moolenaar2912abb2019-03-29 14:16:42 +01008" Get text on the screen, without composing characters.
Bram Moolenaar544d3bc2017-02-05 21:14:50 +01009" ScreenLines(lnum, width) or
10" ScreenLines([start, end], width)
11function! 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
25endfunction
26
Bram Moolenaar2912abb2019-03-29 14:16:42 +010027" Get text on the screen, including composing characters.
28" ScreenLines(lnum, width) or
29" ScreenLines([start, end], width)
30function! 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
44endfunction
45
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020046function! 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
60endfunction
61
Bram Moolenaar544d3bc2017-02-05 21:14:50 +010062function! NewWindow(height, width) abort
63 exe a:height . 'new'
64 exe a:width . 'vsp'
65 redraw!
66endfunction
67
68function! CloseWindow() abort
69 bw!
70 redraw!
71endfunction