ui: Reimplement :suspend command for remote UIs.

- Remove suspend method from the UI protocol
- Handle `:suspend` by disconnecting the last channel that sent a request to
  nvim.
This commit is contained in:
Thiago de Arruda 2015-01-09 09:51:11 -03:00
parent abc147a977
commit d992213678
7 changed files with 15 additions and 21 deletions

View File

@ -71,6 +71,7 @@
#include "nvim/os/time.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/mouse.h"
#include "nvim/msgpack_rpc/channel.h"
static int quitmore = 0;
static int ex_pressedreturn = FALSE;
@ -5398,10 +5399,16 @@ static void ex_stop(exarg_T *eap)
/*
* Disallow suspending for "rvim".
*/
if (!check_restricted()
) {
if (!eap->forceit)
if (!check_restricted()) {
if (!eap->forceit) {
autowrite_all();
}
if (abstract_ui) {
channel_close(last_message_source);
return;
}
windgoto((int)Rows - 1, 0);
out_char('\n');
out_flush();

View File

@ -1245,6 +1245,9 @@ EXTERN int curr_tmode INIT(= TMODE_COOK); /* contains current terminal mode */
EXTERN bool embedded_mode INIT(= false);
// Using the "abstract_ui" termcap
EXTERN bool abstract_ui INIT(= false);
// Id of the last channel sent a message to nvim. Used to determine the target
// of channel-specific actions such as suspending
EXTERN uint64_t last_message_source INIT(= 0);
/// Used to track the status of external functions.
/// Currently only used for iconv().

View File

@ -485,6 +485,7 @@ static void on_request_event(Event event)
{
RequestEvent *e = event.data;
Channel *channel = e->channel;
last_message_source = channel->id;
MsgpackRpcRequestHandler handler = e->handler;
Array args = e->args;
uint64_t request_id = e->request_id;

View File

@ -97,7 +97,6 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id,
ui->update_fg = remote_ui_update_fg;
ui->update_bg = remote_ui_update_bg;
ui->flush = remote_ui_flush;
ui->suspend = remote_ui_suspend;
pmap_put(uint64_t)(connected_uis, channel_id, ui);
ui_attach(ui);
return NIL;
@ -319,9 +318,3 @@ static void remote_ui_flush(UI *ui)
channel_send_event(data->channel_id, "redraw", data->buffer);
data->buffer = (Array)ARRAY_DICT_INIT;
}
static void remote_ui_suspend(UI *ui)
{
UIData *data = ui->data;
remote_ui_disconnect(data->channel_id);
}

View File

@ -117,9 +117,7 @@ void ui_write(uint8_t *s, int len)
*/
void ui_suspend(void)
{
if (abstract_ui) {
UI_CALL(suspend);
} else {
if (!abstract_ui) {
mch_suspend();
}
}

View File

@ -35,7 +35,6 @@ struct ui_t {
void (*flush)(UI *ui);
void (*update_fg)(UI *ui, int fg);
void (*update_bg)(UI *ui, int bg);
void (*suspend)(UI *ui);
};
#ifdef INCLUDE_GENERATED_DECLARATIONS

View File

@ -99,7 +99,6 @@ function Screen.new(width, height)
_mouse_enabled = true,
_bell = false,
_visual_bell = false,
_suspended = true,
_attrs = {},
_cursor = {
enabled = true, row = 1, col = 1
@ -116,12 +115,10 @@ 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:expect(expected, attr_ids)
@ -286,10 +283,6 @@ function Screen:_handle_update_bg(bg)
self._bg = bg
end
function Screen:_handle_suspend()
self._suspended = true
end
function Screen:_clear_block(top, lines, left, columns)
for i = top, top + lines - 1 do
self:_clear_row_section(i, left, left + columns - 1)