xref: /vim-8.2.3635/src/testdir/view_util.vim (revision bffba7f7)
1" Functions about view shared by several tests
2
3" Only load this script once.
4if exists('*Screenline')
5  finish
6endif
7
8" Get line "lnum" as displayed on the screen.
9" Trailing white space is trimmed.
10func Screenline(lnum)
11  let chars = []
12  for c in range(1, winwidth(0))
13    call add(chars, nr2char(screenchar(a:lnum, c)))
14  endfor
15  let line = join(chars, '')
16  return matchstr(line, '^.\{-}\ze\s*$')
17endfunc
18
19" Get text on the screen, including composing characters.
20" ScreenLines(lnum, width) or
21" ScreenLines([start, end], width)
22function! ScreenLines(lnum, width) abort
23  redraw!
24  if type(a:lnum) == v:t_list
25    let start = a:lnum[0]
26    let end = a:lnum[1]
27  else
28    let start = a:lnum
29    let end = a:lnum
30  endif
31  let lines = []
32  for l in range(start, end)
33    let lines += [join(map(range(1, a:width), 'screenstring(l, v:val)'), '')]
34  endfor
35  return lines
36endfunction
37
38function! ScreenAttrs(lnum, width) abort
39  redraw!
40  if type(a:lnum) == v:t_list
41    let start = a:lnum[0]
42    let end = a:lnum[1]
43  else
44    let start = a:lnum
45    let end = a:lnum
46  endif
47  let attrs = []
48  for l in range(start, end)
49    let attrs += [map(range(1, a:width), 'screenattr(l, v:val)')]
50  endfor
51  return attrs
52endfunction
53
54function! NewWindow(height, width) abort
55  exe a:height . 'new'
56  exe a:width . 'vsp'
57  set winfixwidth winfixheight
58  redraw!
59endfunction
60
61function! CloseWindow() abort
62  bw!
63  redraw!
64endfunction
65