view_util.vim (1387B)
1 " Functions about view shared by several tests 2 3 " Only load this script once. 4 if exists('*Screenline') 5 finish 6 endif 7 8 " Get line "lnum" as displayed on the screen. 9 " Trailing white space is trimmed. 10 func 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*$') 17 endfunc 18 19 " Get text on the screen, including composing characters. 20 " ScreenLines(lnum, width) or 21 " ScreenLines([start, end], width) 22 func 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 36 endfunc 37 38 func 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 52 endfunc 53 54 func NewWindow(height, width) abort 55 exe a:height . 'new' 56 exe a:width . 'vsp' 57 set winfixwidth winfixheight 58 redraw! 59 endfunc 60 61 func CloseWindow() abort 62 bw! 63 redraw! 64 endfunc