2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-03-25 05:14:47 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
local thelpers = require('test.functional.terminal.helpers')
|
|
|
|
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
|
2017-04-08 14:12:26 -07:00
|
|
|
local nvim_dir, command = helpers.nvim_dir, helpers.command
|
2015-07-14 08:40:33 -07:00
|
|
|
local eq, eval = helpers.eq, helpers.eval
|
2015-03-25 05:14:47 -07:00
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
describe(':terminal window highlighting', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(50, 7)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = {foreground = 45},
|
|
|
|
[2] = {background = 46},
|
|
|
|
[3] = {foreground = 45, background = 46},
|
2016-08-09 08:01:56 -07:00
|
|
|
[4] = {bold = true, italic = true, underline = true},
|
|
|
|
[5] = {bold = true},
|
|
|
|
[6] = {foreground = 12},
|
|
|
|
[7] = {bold = true, reverse = true},
|
2016-05-17 13:25:11 -07:00
|
|
|
[8] = {background = 11},
|
2016-08-09 08:01:56 -07:00
|
|
|
[9] = {foreground = 130},
|
|
|
|
[10] = {reverse = true},
|
|
|
|
[11] = {background = 11},
|
2015-03-25 05:14:47 -07:00
|
|
|
})
|
2016-06-08 02:26:06 -07:00
|
|
|
screen:attach({rgb=false})
|
2017-04-08 17:02:25 -07:00
|
|
|
command('enew | call termopen(["'..nvim_dir..'/tty-test"])')
|
|
|
|
feed('i')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2016-08-09 08:01:56 -07:00
|
|
|
{10: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{5:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2015-11-17 14:44:00 -07:00
|
|
|
local function descr(title, attr_num, set_attrs_fn)
|
2015-03-25 05:14:47 -07:00
|
|
|
local function sub(s)
|
2016-08-09 08:01:56 -07:00
|
|
|
local str = s:gsub('NUM', attr_num)
|
|
|
|
return str
|
2015-03-25 05:14:47 -07:00
|
|
|
end
|
|
|
|
|
2016-11-16 16:33:45 -07:00
|
|
|
describe(title, function()
|
2015-03-25 05:14:47 -07:00
|
|
|
before_each(function()
|
|
|
|
set_attrs_fn()
|
|
|
|
thelpers.feed_data('text')
|
|
|
|
thelpers.clear_attrs()
|
|
|
|
thelpers.feed_data('text')
|
|
|
|
end)
|
|
|
|
|
|
|
|
local function pass_attrs()
|
2017-03-28 02:07:58 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
2016-08-09 08:01:56 -07:00
|
|
|
screen:expect(sub([[
|
2015-03-25 05:14:47 -07:00
|
|
|
tty ready |
|
2016-08-09 08:01:56 -07:00
|
|
|
{NUM:text}text{10: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{5:-- TERMINAL --} |
|
|
|
|
]]))
|
2015-03-25 05:14:47 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it('will pass the corresponding attributes', pass_attrs)
|
|
|
|
|
|
|
|
it('will pass the corresponding attributes on scrollback', function()
|
2017-03-28 02:07:58 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
2015-03-25 05:14:47 -07:00
|
|
|
pass_attrs()
|
|
|
|
local lines = {}
|
|
|
|
for i = 1, 8 do
|
|
|
|
table.insert(lines, 'line'..tostring(i))
|
|
|
|
end
|
|
|
|
table.insert(lines, '')
|
|
|
|
thelpers.feed_data(lines)
|
|
|
|
screen:expect([[
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
line6 |
|
|
|
|
line7 |
|
|
|
|
line8 |
|
2016-08-09 08:01:56 -07:00
|
|
|
{10: } |
|
|
|
|
{5:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
feed('<c-\\><c-n>gg')
|
2016-08-09 08:01:56 -07:00
|
|
|
screen:expect(sub([[
|
2015-03-25 05:14:47 -07:00
|
|
|
^tty ready |
|
|
|
|
{NUM:text}textline1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
]]))
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
descr('foreground', 1, function() thelpers.set_fg(45) end)
|
|
|
|
descr('background', 2, function() thelpers.set_bg(46) end)
|
|
|
|
descr('foreground and background', 3, function()
|
|
|
|
thelpers.set_fg(45)
|
|
|
|
thelpers.set_bg(46)
|
|
|
|
end)
|
|
|
|
descr('bold, italics and underline', 4, function()
|
|
|
|
thelpers.set_bold()
|
|
|
|
thelpers.set_italic()
|
|
|
|
thelpers.set_underline()
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
describe('terminal window highlighting with custom palette', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(50, 7)
|
|
|
|
screen:set_default_attr_ids({
|
2018-11-30 13:13:01 -07:00
|
|
|
[1] = {foreground = tonumber('0x123456')},
|
2015-03-25 05:14:47 -07:00
|
|
|
[2] = {foreground = 12},
|
|
|
|
[3] = {bold = true, reverse = true},
|
|
|
|
[5] = {background = 11},
|
|
|
|
[6] = {foreground = 130},
|
|
|
|
[7] = {reverse = true},
|
2016-05-17 13:25:11 -07:00
|
|
|
[8] = {background = 11},
|
2016-08-09 08:01:56 -07:00
|
|
|
[9] = {bold = true},
|
2015-03-25 05:14:47 -07:00
|
|
|
})
|
2016-06-08 02:26:06 -07:00
|
|
|
screen:attach({rgb=true})
|
2015-03-25 05:14:47 -07:00
|
|
|
nvim('set_var', 'terminal_color_3', '#123456')
|
2017-04-08 17:02:25 -07:00
|
|
|
command('enew | call termopen(["'..nvim_dir..'/tty-test"])')
|
|
|
|
feed('i')
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2016-08-09 08:01:56 -07:00
|
|
|
{7: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{9:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will use the custom color', function()
|
2017-03-28 02:07:58 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
2015-03-25 05:14:47 -07:00
|
|
|
thelpers.set_fg(3)
|
|
|
|
thelpers.feed_data('text')
|
|
|
|
thelpers.clear_attrs()
|
|
|
|
thelpers.feed_data('text')
|
|
|
|
screen:expect([[
|
|
|
|
tty ready |
|
2016-08-09 08:01:56 -07:00
|
|
|
{1:text}text{7: } |
|
2015-03-25 05:14:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{9:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
2015-07-14 08:40:33 -07:00
|
|
|
|
|
|
|
describe('synIDattr()', function()
|
|
|
|
local screen
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(50, 7)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black')
|
2016-05-31 02:46:32 -07:00
|
|
|
-- Salmon #fa8072 Maroon #800000
|
2017-04-08 14:12:26 -07:00
|
|
|
command('highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon')
|
2015-07-14 08:40:33 -07:00
|
|
|
end)
|
|
|
|
|
2016-06-18 09:49:50 -07:00
|
|
|
it('returns cterm-color if RGB-capable UI is _not_ attached', function()
|
|
|
|
eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
|
|
|
|
eq('252', eval('synIDattr(hlID("Normal"), "fg#")'))
|
2016-09-11 07:03:22 -07:00
|
|
|
eq('', eval('synIDattr(hlID("Normal"), "bg")'))
|
|
|
|
eq('', eval('synIDattr(hlID("Normal"), "bg#")'))
|
2016-06-18 09:49:50 -07:00
|
|
|
eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
|
|
|
|
eq('79', eval('synIDattr(hlID("Keyword"), "fg#")'))
|
|
|
|
eq('', eval('synIDattr(hlID("Keyword"), "sp")'))
|
|
|
|
eq('', eval('synIDattr(hlID("Keyword"), "sp#")'))
|
2015-07-14 08:40:33 -07:00
|
|
|
end)
|
|
|
|
|
2016-06-18 09:49:50 -07:00
|
|
|
it('returns gui-color if "gui" arg is passed', function()
|
|
|
|
eq('Black', eval('synIDattr(hlID("Normal"), "bg", "gui")'))
|
|
|
|
eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp", "gui")'))
|
|
|
|
end)
|
2016-05-31 02:46:32 -07:00
|
|
|
|
2016-06-18 09:49:50 -07:00
|
|
|
it('returns gui-color if RGB-capable UI is attached', function()
|
2016-06-08 02:26:06 -07:00
|
|
|
screen:attach({rgb=true})
|
2016-06-18 09:49:50 -07:00
|
|
|
eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")'))
|
|
|
|
eq('Black', eval('synIDattr(hlID("Normal"), "bg")'))
|
|
|
|
eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")'))
|
|
|
|
eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp")'))
|
2016-05-31 02:46:32 -07:00
|
|
|
end)
|
|
|
|
|
2016-06-18 09:49:50 -07:00
|
|
|
it('returns #RRGGBB value for fg#/bg#/sp#', function()
|
2016-06-08 02:26:06 -07:00
|
|
|
screen:attach({rgb=true})
|
2016-09-10 03:17:06 -07:00
|
|
|
eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")'))
|
|
|
|
eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")'))
|
2016-05-31 02:46:32 -07:00
|
|
|
eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")'))
|
|
|
|
eq('#800000', eval('synIDattr(hlID("Keyword"), "sp#")'))
|
2015-07-14 08:40:33 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('returns color number if non-GUI', function()
|
2016-06-08 02:26:06 -07:00
|
|
|
screen:attach({rgb=false})
|
2016-06-18 09:49:50 -07:00
|
|
|
eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
|
|
|
|
eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
|
2015-07-14 08:40:33 -07:00
|
|
|
end)
|
|
|
|
end)
|
2016-09-10 03:17:06 -07:00
|
|
|
|
|
|
|
describe('fg/bg special colors', function()
|
|
|
|
local screen
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(50, 7)
|
2017-04-08 14:12:26 -07:00
|
|
|
command('highlight Normal ctermfg=145 ctermbg=16 guifg=#ff0000 guibg=Black')
|
|
|
|
command('highlight Visual ctermfg=bg ctermbg=fg guifg=bg guibg=fg guisp=bg')
|
2016-09-10 03:17:06 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('resolve to "Normal" values', function()
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "bg")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "fg")'))
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "bg#")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "fg#")'))
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "fg")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "bg")'))
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "fg#")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "bg#")'))
|
|
|
|
eq('bg', eval('synIDattr(hlID("Visual"), "fg", "gui")'))
|
|
|
|
eq('bg', eval('synIDattr(hlID("Visual"), "fg#", "gui")'))
|
|
|
|
eq('fg', eval('synIDattr(hlID("Visual"), "bg", "gui")'))
|
|
|
|
eq('fg', eval('synIDattr(hlID("Visual"), "bg#", "gui")'))
|
|
|
|
eq('bg', eval('synIDattr(hlID("Visual"), "sp", "gui")'))
|
|
|
|
eq('bg', eval('synIDattr(hlID("Visual"), "sp#", "gui")'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('resolve to "Normal" values in RGB-capable UI', function()
|
|
|
|
screen:attach({rgb=true})
|
|
|
|
eq('bg', eval('synIDattr(hlID("Visual"), "fg")'))
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "bg#")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "fg#")'))
|
|
|
|
eq('fg', eval('synIDattr(hlID("Visual"), "bg")'))
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "fg#")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "bg#")'))
|
|
|
|
eq('bg', eval('synIDattr(hlID("Visual"), "sp")'))
|
|
|
|
eq(eval('synIDattr(hlID("Normal"), "bg#")'),
|
|
|
|
eval('synIDattr(hlID("Visual"), "sp#")'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('resolve after the "Normal" group is modified', function()
|
|
|
|
screen:attach({rgb=true})
|
|
|
|
local new_guibg = '#282c34'
|
|
|
|
local new_guifg = '#abb2bf'
|
2017-04-08 14:12:26 -07:00
|
|
|
command('highlight Normal guifg='..new_guifg..' guibg='..new_guibg)
|
2016-09-10 03:17:06 -07:00
|
|
|
eq(new_guibg, eval('synIDattr(hlID("Visual"), "fg#")'))
|
|
|
|
eq(new_guifg, eval('synIDattr(hlID("Visual"), "bg#")'))
|
|
|
|
eq(new_guibg, eval('synIDattr(hlID("Visual"), "sp#")'))
|
|
|
|
end)
|
|
|
|
end)
|