mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ui: reserve the right to split a screen redraw into multiple batches.
This commit is contained in:
parent
43823acae2
commit
bab3b0ad45
@ -18,9 +18,9 @@ the grid ("externalized").
|
|||||||
|
|
||||||
|
|
||||||
*ui-options*
|
*ui-options*
|
||||||
The |nvim_ui_attach()| API method is used to tell Nvim that your program wants to draw the
|
The |nvim_ui_attach()| API method is used to tell Nvim that your program wants to
|
||||||
Nvim screen grid with a size of width × height cells. This is typically done
|
draw the Nvim screen grid with a size of width × height cells. This is typically
|
||||||
by an embedder, see |ui-startup| below for details, but an UI can also
|
done by an embedder, see |ui-startup| below for details, but an UI can also
|
||||||
connect to a running nvim instance and invoke this method. `options` must be
|
connect to a running nvim instance and invoke this method. `options` must be
|
||||||
a dictionary with these (optional) keys:
|
a dictionary with these (optional) keys:
|
||||||
`rgb` Decides the color format. *ui-rgb*
|
`rgb` Decides the color format. *ui-rgb*
|
||||||
@ -45,13 +45,17 @@ Nvim sends msgpack-rpc notifications to all attached UIs, with method name
|
|||||||
Each update event is itself an array whose first element is the event name and
|
Each update event is itself an array whose first element is the event name and
|
||||||
remaining elements are event-parameter tuples. This allows multiple events of
|
remaining elements are event-parameter tuples. This allows multiple events of
|
||||||
the same kind to be sent in a row without the event name being repeated. This
|
the same kind to be sent in a row without the event name being repeated. This
|
||||||
batching is mostly used for "put", because each "put" event puts contents in
|
batching is mostly used for "grid_line", because each "grid_line" event puts
|
||||||
one screen cell, but clients must be prepared for multiple argument sets being
|
contents in one screen line, but clients must be prepared for multiple argument
|
||||||
batched for all event kinds.
|
sets being batched for all event kinds.
|
||||||
|
|
||||||
Events must be handled in-order. The user should only see the updated screen
|
Events must be handled in-order. A "flush" event is sent when nvim is done
|
||||||
state after all events in the same "redraw" batch are processed (not any
|
redrawing the entire screen (so that all windows have a consistent view of
|
||||||
intermediate state after processing only part of the array).
|
buffer state, options etc). Clients should be prepared that several "redraw"
|
||||||
|
batches are sent before the entire screen has been redrawn, and only the last
|
||||||
|
batch will end in "flush". The user should only see the final state when
|
||||||
|
"flush" is sent, and not any intermediate state after processing only part of
|
||||||
|
the batch array, nor after a batch not ending with "flush".
|
||||||
|
|
||||||
By default, Nvim sends |ui-global| and |ui-grid-old| events; these suffice to
|
By default, Nvim sends |ui-global| and |ui-grid-old| events; these suffice to
|
||||||
implement a terminal-like interface. However there are two revisions of the
|
implement a terminal-like interface. However there are two revisions of the
|
||||||
@ -81,7 +85,7 @@ to do early initialization. As soon as the UI invokes |nvim_ui_attach()|, the
|
|||||||
startup will continue.
|
startup will continue.
|
||||||
|
|
||||||
A simple UI only need to do a single |nvim_ui_attach()| request and then
|
A simple UI only need to do a single |nvim_ui_attach()| request and then
|
||||||
be prepared to handle any UI event. A more featureful UI, which might do
|
be prepared to handle any UI event. A more featureful UI, which might need
|
||||||
additional configuration of the nvim process, should use the following startup
|
additional configuration of the nvim process, should use the following startup
|
||||||
procedure:
|
procedure:
|
||||||
|
|
||||||
@ -199,6 +203,11 @@ the editor.
|
|||||||
["visual_bell"]
|
["visual_bell"]
|
||||||
Notify the user with an audible or visual bell, respectively.
|
Notify the user with an audible or visual bell, respectively.
|
||||||
|
|
||||||
|
["flush"]
|
||||||
|
Nvim is done redrawing the screen. For an implementation that renders
|
||||||
|
to an internal buffer, this is the time to display the redrawn parts
|
||||||
|
to the user.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
Grid Events (line-based) *ui-linegrid*
|
Grid Events (line-based) *ui-linegrid*
|
||||||
|
|
||||||
|
@ -511,6 +511,7 @@ static void remote_ui_flush(UI *ui)
|
|||||||
if (!ui->ui_ext[kUILinegrid]) {
|
if (!ui->ui_ext[kUILinegrid]) {
|
||||||
remote_ui_cursor_goto(ui, data->cursor_row, data->cursor_col);
|
remote_ui_cursor_goto(ui, data->cursor_row, data->cursor_col);
|
||||||
}
|
}
|
||||||
|
push_call(ui, "flush", (Array)ARRAY_DICT_INIT);
|
||||||
rpc_send_event(data->channel_id, "redraw", data->buffer);
|
rpc_send_event(data->channel_id, "redraw", data->buffer);
|
||||||
data->buffer = (Array)ARRAY_DICT_INIT;
|
data->buffer = (Array)ARRAY_DICT_INIT;
|
||||||
}
|
}
|
||||||
|
@ -386,9 +386,13 @@ function Screen:wait(check, timeout)
|
|||||||
local err, checked = false
|
local err, checked = false
|
||||||
local success_seen = false
|
local success_seen = false
|
||||||
local failure_after_success = false
|
local failure_after_success = false
|
||||||
|
local did_flush = true
|
||||||
local function notification_cb(method, args)
|
local function notification_cb(method, args)
|
||||||
assert(method == 'redraw')
|
assert(method == 'redraw')
|
||||||
self:_redraw(args)
|
did_flush = self:_redraw(args)
|
||||||
|
if not did_flush then
|
||||||
|
return
|
||||||
|
end
|
||||||
err = check()
|
err = check()
|
||||||
checked = true
|
checked = true
|
||||||
if not err then
|
if not err then
|
||||||
@ -402,7 +406,9 @@ function Screen:wait(check, timeout)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
run(nil, notification_cb, nil, timeout or self.timeout)
|
run(nil, notification_cb, nil, timeout or self.timeout)
|
||||||
if not checked then
|
if not did_flush then
|
||||||
|
err = "no flush received"
|
||||||
|
elseif not checked then
|
||||||
err = check()
|
err = check()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -431,7 +437,8 @@ function Screen:sleep(ms)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Screen:_redraw(updates)
|
function Screen:_redraw(updates)
|
||||||
for _, update in ipairs(updates) do
|
local did_flush = false
|
||||||
|
for k, update in ipairs(updates) do
|
||||||
-- print('--')
|
-- print('--')
|
||||||
-- print(require('inspect')(update))
|
-- print(require('inspect')(update))
|
||||||
local method = update[1]
|
local method = update[1]
|
||||||
@ -446,7 +453,11 @@ function Screen:_redraw(updates)
|
|||||||
self._on_event(method, update[i])
|
self._on_event(method, update[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if k == #updates and method == "flush" then
|
||||||
|
did_flush = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return did_flush
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:set_on_event_handler(callback)
|
function Screen:set_on_event_handler(callback)
|
||||||
@ -472,6 +483,10 @@ function Screen:_handle_resize(width, height)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Screen:_handle_flush()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Screen:_handle_grid_resize(grid, width, height)
|
function Screen:_handle_grid_resize(grid, width, height)
|
||||||
assert(grid == 1)
|
assert(grid == 1)
|
||||||
self:_handle_resize(width, height)
|
self:_handle_resize(width, height)
|
||||||
|
Loading…
Reference in New Issue
Block a user