xref: /vim-8.2.3635/src/testdir/view_util.vim (revision 2912abb3)
1" Functions about view shared by several tests
2
3" Only load this script once.
4if exists('*ScreenLines')
5  finish
6endif
7
8" Get text on the screen, without composing characters.
9" 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
27" 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
46function! 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
62function! 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
72