aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui/screen.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/ui/screen.lua')
-rw-r--r--test/functional/ui/screen.lua81
1 files changed, 38 insertions, 43 deletions
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 3a39cd0aa6..105e43843c 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -105,26 +105,22 @@ function Screen.new(width, height)
if not height then
height = 14
end
- return setmetatable({
+ local self = setmetatable({
+ title = '',
+ icon = '',
+ bell = false,
+ visual_bell = false,
+ suspended = false,
_default_attr_ids = nil,
- _width = width,
- _height = height,
- _rows = new_cell_grid(width, height),
_mode = 'normal',
_mouse_enabled = true,
- _bell = false,
- _visual_bell = false,
- _suspended = true,
- _title = nil,
- _icon = nil,
_attrs = {},
_cursor = {
enabled = true, row = 1, col = 1
- },
- _scroll_region = {
- top = 1, bot = height, left = 1, right = width
}
}, Screen)
+ self:_handle_resize(width, height)
+ return self
end
function Screen:set_default_attr_ids(attr_ids)
@@ -133,12 +129,14 @@ end
function Screen:attach()
request('ui_attach', self._width, self._height, true)
- self._suspended = false
end
function Screen:detach()
request('ui_detach')
- self._suspended = true
+end
+
+function Screen:try_resize(columns, rows)
+ request('ui_try_resize', columns, rows)
end
function Screen:expect(expected, attr_ids)
@@ -151,7 +149,7 @@ function Screen:expect(expected, attr_ids)
table.insert(expected_rows, row)
end
local ids = attr_ids or self._default_attr_ids
- self:_wait(function()
+ self:wait(function()
for i = 1, self._height do
local expected_row = expected_rows[i]
local actual_row = self:_row_repr(self._rows[i], ids)
@@ -163,7 +161,7 @@ function Screen:expect(expected, attr_ids)
end)
end
-function Screen:_wait(check, timeout)
+function Screen:wait(check, timeout)
local err, checked = false
local function notification_cb(method, args)
assert(method == 'redraw')
@@ -198,7 +196,20 @@ function Screen:_redraw(updates)
end
function Screen:_handle_resize(width, height)
- self._rows = new_cell_grid(width, height)
+ local rows = {}
+ for i = 1, height do
+ local cols = {}
+ for j = 1, width do
+ table.insert(cols, {text = ' ', attrs = {}})
+ end
+ table.insert(rows, cols)
+ end
+ self._rows = rows
+ self._width = width
+ self._height = height
+ self._scroll_region = {
+ top = 1, bot = height, left = 1, right = width
+ }
end
function Screen:_handle_clear()
@@ -268,11 +279,14 @@ function Screen:_handle_scroll(count)
for i = start, stop, step do
local target = self._rows[i]
local source = self._rows[i + count]
- self:_copy_row_section(target, source, left, right)
+ for j = left, right do
+ target[j].text = source[j].text
+ target[j].attrs = source[j].attrs
+ end
end
-- clear invalid rows
- for i = stop + 1, stop + count, step do
+ for i = stop + step, stop + count, step do
self:_clear_row_section(i, left, right)
end
end
@@ -289,11 +303,11 @@ function Screen:_handle_put(str)
end
function Screen:_handle_bell()
- self._bell = true
+ self.bell = true
end
function Screen:_handle_visual_bell()
- self._visual_bell = true
+ self.visual_bell = true
end
function Screen:_handle_update_fg(fg)
@@ -305,15 +319,15 @@ function Screen:_handle_update_bg(bg)
end
function Screen:_handle_suspend()
- self._suspended = true
+ self.suspended = true
end
function Screen:_handle_set_title(title)
- self._title = title
+ self.title = title
end
function Screen:_handle_set_icon(icon)
- self._icon = icon
+ self.icon = icon
end
function Screen:_clear_block(top, lines, left, columns)
@@ -330,13 +344,6 @@ function Screen:_clear_row_section(rownum, startcol, stopcol)
end
end
-function Screen:_copy_row_section(target, source, startcol, stopcol)
- for i = startcol, stopcol do
- target[i].text = source[i].text
- target[i].attrs = source[i].attrs
- end
-end
-
function Screen:_row_repr(row, attr_ids)
local rv = {}
local current_attr_id
@@ -387,18 +394,6 @@ function backward_find_meaningful(tbl, from)
return from
end
-function new_cell_grid(width, height)
- local rows = {}
- for i = 1, height do
- local cols = {}
- for j = 1, width do
- table.insert(cols, {text = ' ', attrs = {}})
- end
- table.insert(rows, cols)
- end
- return rows
-end
-
function get_attr_id(attr_ids, attrs)
if not attr_ids then
return