2017-07-28 16:46:43 -07:00
|
|
|
" Functions about view shared by several tests
|
|
|
|
|
2018-07-14 10:32:51 -07:00
|
|
|
" Only load this script once.
|
2020-04-28 20:13:23 -07:00
|
|
|
if exists('*Screenline')
|
2018-07-14 10:32:51 -07:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2020-04-28 20:13:23 -07:00
|
|
|
" Get line "lnum" as displayed on the screen.
|
|
|
|
" Trailing white space is trimmed.
|
|
|
|
func Screenline(lnum)
|
|
|
|
let chars = []
|
|
|
|
for c in range(1, winwidth(0))
|
|
|
|
call add(chars, nr2char(screenchar(a:lnum, c)))
|
|
|
|
endfor
|
|
|
|
let line = join(chars, '')
|
|
|
|
return matchstr(line, '^.\{-}\ze\s*$')
|
|
|
|
endfunc
|
|
|
|
|
2017-07-28 16:46:43 -07:00
|
|
|
" ScreenLines(lnum, width) or
|
|
|
|
" ScreenLines([start, end], width)
|
|
|
|
function! ScreenLines(lnum, width) abort
|
|
|
|
redraw!
|
|
|
|
if type(a:lnum) == v:t_list
|
|
|
|
let start = a:lnum[0]
|
|
|
|
let end = a:lnum[1]
|
|
|
|
else
|
|
|
|
let start = a:lnum
|
|
|
|
let end = a:lnum
|
|
|
|
endif
|
|
|
|
let lines = []
|
|
|
|
for l in range(start, end)
|
|
|
|
let lines += [join(map(range(1, a:width), 'nr2char(screenchar(l, v:val))'), '')]
|
|
|
|
endfor
|
|
|
|
return lines
|
|
|
|
endfunction
|
|
|
|
|
2018-07-14 10:32:51 -07:00
|
|
|
function! ScreenAttrs(lnum, width) abort
|
|
|
|
redraw!
|
|
|
|
if type(a:lnum) == v:t_list
|
|
|
|
let start = a:lnum[0]
|
|
|
|
let end = a:lnum[1]
|
|
|
|
else
|
|
|
|
let start = a:lnum
|
|
|
|
let end = a:lnum
|
|
|
|
endif
|
|
|
|
let attrs = []
|
|
|
|
for l in range(start, end)
|
|
|
|
let attrs += [map(range(1, a:width), 'screenattr(l, v:val)')]
|
|
|
|
endfor
|
|
|
|
return attrs
|
|
|
|
endfunction
|
|
|
|
|
2017-07-28 16:46:43 -07:00
|
|
|
function! NewWindow(height, width) abort
|
|
|
|
exe a:height . 'new'
|
|
|
|
exe a:width . 'vsp'
|
2019-09-21 20:29:15 -07:00
|
|
|
set winfixwidth winfixheight
|
2017-07-28 16:46:43 -07:00
|
|
|
redraw!
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! CloseWindow() abort
|
|
|
|
bw!
|
|
|
|
redraw!
|
|
|
|
endfunction
|