multigrid: add tests for multiline messages and tabs

This commit is contained in:
Björn Linse 2018-11-18 10:00:27 +01:00
parent ed3da23cf4
commit 44b8e58f33
2 changed files with 543 additions and 7 deletions

View File

@ -4,9 +4,6 @@ local spawn, set_session = helpers.spawn, helpers.set_session
local feed, command, insert = helpers.feed, helpers.command, helpers.insert
local eq = helpers.eq
-- Note 1:
-- Global grid i.e. "grid 1" shows some unwanted elements because they are
-- not cleared when they are expected to be drawn over by window grids.
describe('multigrid screen', function()
local screen
@ -33,8 +30,13 @@ describe('multigrid screen', function()
[11] = {bold = true, reverse = true},
[12] = {reverse = true},
[13] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
[14] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
[15] = {bold = true, foreground = Screen.colors.SeaGreen4},
[16] = {background = Screen.colors.LightGrey, underline = true},
[17] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta},
[18] = {bold = true, foreground = Screen.colors.Magenta},
[19] = {foreground = Screen.colors.Brown},
})
screen.win_position = {}
end)
after_each(function()
@ -826,6 +828,7 @@ describe('multigrid screen', function()
end)
end)
describe('with resized grid', function()
before_each(function()
screen:try_resize_grid(2, 60, 20)
@ -1000,4 +1003,526 @@ describe('multigrid screen', function()
]])
end)
end)
it('multiline messages scroll over windows', function()
command('sp')
command('vsp')
screen:expect([[
## grid 1
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
{11:[No Name] }{12:[No Name] }|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
feed(":echoerr 'very' | echoerr 'much' | echoerr 'fail'<cr>")
screen:expect([[
## grid 1
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
{11:[No Name] }{12:[No Name] }|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{11: }|
{14:very} |
{14:much} |
{14:fail} |
{15:Press ENTER or type command to continue}^ |
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
feed('<cr>')
screen:expect([[
## grid 1
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
{11:[No Name] }{12:[No Name] }|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command([[
func! ErrMsg()
for i in range(12)
echoerr "error ".i
endfor
endfunc]])
feed(":call ErrMsg()<cr>")
screen:expect([[
## grid 1
{14:Error detected while processing function ErrMsg:} |
{19:line 2:} |
{14:error 0} |
{14:error 1} |
{14:error 2} |
{14:error 3} |
{14:error 4} |
{14:error 5} |
{14:error 6} |
{14:error 7} |
{14:error 8} |
{14:error 9} |
{14:error 10} |
{15:-- More --}^ |
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
feed("<c-c>")
screen:expect([[
## grid 1
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
[4:--------------------------]{12:│}[3:--------------------------]|
{11:[No Name] }{12:[No Name] }|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
[2:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
it('handles switich tabs', function()
command('vsp')
screen:expect([[
## grid 1
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] }{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command('tabnew')
-- note the old grids aren't resized yet
screen:expect([[
## grid 1
{16: }{17:2}{16: [No Name] }{7: [No Name] }{12: }{16:X}|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
{11:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command('sp')
screen:expect([[
## grid 1
{16: }{17:2}{16: [No Name] }{7: }{18:2}{7: [No Name] }{12: }{16:X}|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
{11:[No Name] }|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 5
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command('tabnext')
screen:expect([[
## grid 1
{7: }{18:2}{7: [No Name] }{16: }{17:2}{16: [No Name] }{12: }{16:X}|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] }{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 5
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command('tabnext')
screen:expect([[
## grid 1
{16: }{17:2}{16: [No Name] }{7: }{18:2}{7: [No Name] }{12: }{16:X}|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
[5:-----------------------------------------------------]|
{11:[No Name] }|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
[4:-----------------------------------------------------]|
{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 4
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 5
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
command('tabclose')
screen:expect([[
## grid 1
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
[3:--------------------------]{12:│}[2:--------------------------]|
{11:[No Name] }{12:[No Name] }|
|
## grid 2
|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
]])
end)
end)

View File

@ -157,7 +157,7 @@ function Screen.new(width, height)
cmdline_block = {},
wildmenu_items = nil,
wildmenu_selected = nil,
win_position = nil,
win_position = {},
_session = nil,
_default_attr_ids = nil,
_default_attr_ignore = nil,
@ -647,10 +647,13 @@ function Screen:_handle_grid_resize(grid, width, height)
}
end
function Screen:_handle_msg_scroll_start()
function Screen:_handle_win_scroll_over_start()
self.scroll_over = true
self.scroll_over_pos = self._grids[1].height
end
function Screen:_handle_msg_scroll_reset()
function Screen:_handle_win_scroll_over_reset()
self.scroll_over = false
end
function Screen:_handle_flush()
@ -763,12 +766,17 @@ function Screen:_handle_scroll(count)
end
function Screen:_handle_grid_scroll(g, top, bot, left, right, rows, cols)
if self.scroll_over and g == 1 and top < self.scroll_over_pos then
self.scroll_over_pos = top
end
top = top+1
left = left+1
assert(cols == 0)
local grid = self._grids[g]
local start, stop, step
if rows > 0 then
start = top
stop = bot - rows
@ -985,6 +993,9 @@ function Screen:_row_repr(gridnr, rownr, attr_state, cursor)
local current_attr_id
local i = 1
local has_windows = self._options.ext_multigrid and gridnr == 1
if self.scroll_over and self.scroll_over_pos < rownr then
has_windows = false
end
local row = self._grids[gridnr].rows[rownr]
while i <= #row do
local did_window = false