robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
af23d17388
master
1" Functions about view shared by several tests 2 3" Only load this script once. 4if exists ( '*Screenline' ) 5finish 6endif 7 8" Get line "lnum" as displayed on the screen. 9" Trailing white space is trimmed. 10func Screenline ( lnum ) 11let chars = [] 12for c in range ( 1 , winwidth ( 0 )) 13call add ( chars , nr2char ( screenchar ( a: lnum , c ))) 14endfor 15let line = join ( chars , '' ) 16return 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) 22func ScreenLines ( lnum , width ) abort 23redraw ! 24if type ( a: lnum ) == v: t_list 25let start = a: lnum [ 0 ] 26let end = a: lnum [ 1 ] 27else 28let start = a: lnum 29let end = a: lnum 30endif 31let lines = [] 32for l in range ( start , end ) 33let lines += [ join ( map ( range ( 1 , a: width ), 'screenstring(l, v:val)' ), '' )] 34endfor 35return lines 36endfunc 37 38func ScreenAttrs ( lnum , width ) abort 39redraw ! 40if type ( a: lnum ) == v: t_list 41let start = a: lnum [ 0 ] 42let end = a: lnum [ 1 ] 43else 44let start = a: lnum 45let end = a: lnum 46endif 47let attrs = [] 48for l in range ( start , end ) 49let attrs += [ map ( range ( 1 , a: width ), 'screenattr(l, v:val)' )] 50endfor 51return attrs 52endfunc 53 54func NewWindow ( height , width ) abort 55exe a: height . 'new' 56exe a: width . 'vsp' 57set winfixwidth winfixheight 58redraw ! 59endfunc 60 61func CloseWindow () abort 62bw ! 63redraw ! 64endfunc