1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local feed = helpers.feed
local clear = helpers.clear
local meths = helpers.meths
local source = helpers.source
local screen
before_each(function()
clear()
screen = Screen.new(40, 2)
screen:attach()
source([[
highlight RBP1 guifg=Red
highlight RBP2 guifg=Yellow
highlight RBP3 guifg=Green
highlight RBP4 guifg=Blue
let g:NUM_LVLS = 4
function Redraw()
redraw!
return ''
endfunction
cnoremap <expr> {REDRAW} Redraw()
function RainBowParens(cmdline)
let ret = []
let i = 0
let lvl = 0
while i < len(a:cmdline)
if a:cmdline[i] is# '('
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
let lvl += 1
elseif a:cmdline[i] is# ')'
let lvl -= 1
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
endif
let i += 1
endwhile
return ret
endfunction
]])
screen:set_default_attr_ids({
RBP1={foreground = Screen.colors.Red},
RBP2={foreground = Screen.colors.Yellow},
RBP3={foreground = Screen.colors.Green},
RBP4={foreground = Screen.colors.Blue},
})
end)
describe('Command-line coloring', function()
it('works', function()
meths.set_var('Nvim_color_cmdline', 'RainBowParens')
meths.set_option('more', false)
feed(':')
screen:expect([[
|
:^ |
]])
feed('e')
screen:expect([[
|
:e^ |
]])
feed('cho ')
screen:expect([[
|
:echo ^ |
]])
feed('(')
screen:expect([[
|
:echo {RBP1:(}^ |
]])
feed('(')
screen:expect([[
|
:echo {RBP1:(}{RBP2:(}^ |
]])
feed('42')
screen:expect([[
|
:echo {RBP1:(}{RBP2:(}42^ |
]])
feed('))')
screen:expect([[
|
:echo {RBP1:(}{RBP2:(}42{RBP2:)}{RBP1:)}^ |
]])
feed('<BS>')
screen:expect([[
|
:echo {RBP1:(}{RBP2:(}42{RBP2:)}^ |
]])
feed('{REDRAW}')
screen:expect([[
|
:echo {RBP1:(}{RBP2:(}42{RBP2:)}^ |
]])
end)
end)
|