mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 09:56:31 +00:00
UIAttach, UIDetach
This commit is contained in:

committed by
Justin M. Keyes

parent
426399c2c4
commit
e9cf515888
@@ -280,8 +280,8 @@ Name triggered by ~
|
||||
|
||||
Startup and exit
|
||||
|VimEnter| after doing all the startup stuff
|
||||
|GUIEnter| after starting the GUI successfully
|
||||
|GUIFailed| after starting the GUI failed
|
||||
|UIAttach| after a new UI attaches
|
||||
|UIDetach| after a UI detaches
|
||||
|TermResponse| after the terminal response to t_RV is received
|
||||
|QuitPre| when using `:quit`, before deciding whether to exit
|
||||
|ExitPre| when using a command that may make Vim exit
|
||||
@@ -805,19 +805,14 @@ FuncUndefined When a user function is used but it isn't
|
||||
NOTE: When writing Vim scripts a better
|
||||
alternative is to use an autoloaded function.
|
||||
See |autoload-functions|.
|
||||
*GUIEnter*
|
||||
GUIEnter After starting the GUI successfully, and after
|
||||
opening the window. It is triggered before
|
||||
VimEnter when using gvim. Can be used to
|
||||
position the window from a gvimrc file: >
|
||||
:autocmd GUIEnter * winpos 100 50
|
||||
< *GUIFailed*
|
||||
GUIFailed After starting the GUI failed. Vim may
|
||||
continue to run in the terminal, if possible
|
||||
(only on Unix and alikes, when connecting the
|
||||
X server fails). You may want to quit Vim: >
|
||||
:autocmd GUIFailed * qall
|
||||
< *InsertChange*
|
||||
{Nvim} *UIAttach*
|
||||
UIAttach After a new UI connects to nvim and successfully
|
||||
calls |nvim_ui_attach|. Sets chan in |v:event| with
|
||||
the channel id or 0 if using the internal UI.
|
||||
{Nvim} *UIDetach*
|
||||
UIDetach After a UI detaches from nvim. Sets chan in |v:event|
|
||||
with the channel id or 0 if using the internal UI.
|
||||
*InsertChange*
|
||||
InsertChange When typing <Insert> while in Insert or
|
||||
Replace mode. The |v:insertmode| variable
|
||||
indicates the new mode.
|
||||
|
@@ -28,6 +28,8 @@ Environment Variables ~
|
||||
Events ~
|
||||
*EncodingChanged* Never fired; 'encoding' is always "utf-8".
|
||||
*FileEncoding* Never fired; equivalent to |EncodingChanged|.
|
||||
*GUIEnter* Never fired; Use |UIAttach| instead.
|
||||
*GUIFailed* Never fired.
|
||||
|
||||
Keycodes ~
|
||||
*<MouseDown>* Use <ScrollWheelUp> instead.
|
||||
|
@@ -154,6 +154,8 @@ Events:
|
||||
|TermClose|
|
||||
|TermOpen|
|
||||
|TextYankPost|
|
||||
|UIAttach|
|
||||
|UIDetach|
|
||||
|VimResume|
|
||||
|VimSuspend|
|
||||
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#include "nvim/highlight.h"
|
||||
#include "nvim/screen.h"
|
||||
#include "nvim/window.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/eval.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "api/ui.c.generated.h"
|
||||
@@ -169,6 +171,12 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
||||
|
||||
pmap_put(uint64_t)(connected_uis, channel_id, ui);
|
||||
ui_attach_impl(ui);
|
||||
|
||||
dict_T *dict = get_vim_var_dict(VV_EVENT);
|
||||
tv_dict_add_nr(dict, S_LEN("chan"), (long)channel_id);
|
||||
tv_dict_set_keys_readonly(dict);
|
||||
apply_autocmds(EVENT_UIATTACH, NULL, NULL, false, curbuf);
|
||||
tv_dict_clear(dict);
|
||||
}
|
||||
|
||||
/// @deprecated
|
||||
@@ -196,6 +204,12 @@ void nvim_ui_detach(uint64_t channel_id, Error *err)
|
||||
return;
|
||||
}
|
||||
remote_ui_disconnect(channel_id);
|
||||
|
||||
dict_T *dict = get_vim_var_dict(VV_EVENT);
|
||||
tv_dict_add_nr(dict, S_LEN("chan"), (long)channel_id);
|
||||
tv_dict_set_keys_readonly(dict);
|
||||
apply_autocmds(EVENT_UIDETACH, NULL, NULL, false, curbuf);
|
||||
tv_dict_clear(dict);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -96,6 +96,8 @@ return {
|
||||
'TextChangedI', -- text was modified in Insert mode(no popup)
|
||||
'TextChangedP', -- text was modified in Insert mode(popup)
|
||||
'TextYankPost', -- after a yank or delete was done (y, d, c)
|
||||
'UIAttach', -- after a UI attached
|
||||
'UIDetach', -- after a UI detaches
|
||||
'User', -- user defined autocommand
|
||||
'VimEnter', -- after starting Vim
|
||||
'VimLeave', -- before exiting Vim
|
||||
@@ -123,5 +125,7 @@ return {
|
||||
TabNewEntered=true,
|
||||
TermClose=true,
|
||||
TermOpen=true,
|
||||
UIAttach=true,
|
||||
UIDetach=true,
|
||||
},
|
||||
}
|
||||
|
@@ -172,6 +172,7 @@ static Channel *channel_alloc(ChannelStreamType type)
|
||||
chan->refcount = 1;
|
||||
chan->exit_status = -1;
|
||||
chan->streamtype = type;
|
||||
assert(chan->id <= VARNUMBER_MAX);
|
||||
pmap_put(uint64_t)(channels, chan->id, chan);
|
||||
return chan;
|
||||
}
|
||||
@@ -190,6 +191,7 @@ void channel_create_event(Channel *chan, const char *ext_source)
|
||||
source = (const char *)IObuff;
|
||||
}
|
||||
|
||||
assert(chan->id <= VARNUMBER_MAX);
|
||||
Dictionary info = channel_info(chan->id);
|
||||
typval_T tv = TV_INITIAL_VALUE;
|
||||
// TODO(bfredl): do the conversion in one step. Also would be nice
|
||||
|
@@ -17,6 +17,8 @@
|
||||
#include "nvim/ui_bridge.h"
|
||||
#include "nvim/ugrid.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/fileio.h"
|
||||
#include "nvim/eval.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "ui_bridge.c.generated.h"
|
||||
@@ -86,6 +88,13 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
|
||||
uv_mutex_unlock(&rv->mutex);
|
||||
|
||||
ui_attach_impl(&rv->bridge);
|
||||
|
||||
dict_T *dict = get_vim_var_dict(VV_EVENT);
|
||||
tv_dict_add_nr(dict, S_LEN("chan"), 0);
|
||||
tv_dict_set_keys_readonly(dict);
|
||||
apply_autocmds(EVENT_UIATTACH, NULL, NULL, false, curbuf);
|
||||
tv_dict_clear(dict);
|
||||
|
||||
return &rv->bridge;
|
||||
}
|
||||
|
||||
@@ -107,6 +116,13 @@ static void ui_bridge_stop(UI *b)
|
||||
// Detach bridge first, so that "stop" is the last event the TUI loop
|
||||
// receives from the main thread. #8041
|
||||
ui_detach_impl(b);
|
||||
|
||||
dict_T *dict = get_vim_var_dict(VV_EVENT);
|
||||
tv_dict_add_nr(dict, S_LEN("chan"), 0);
|
||||
tv_dict_set_keys_readonly(dict);
|
||||
apply_autocmds(EVENT_UIDETACH, NULL, NULL, false, curbuf);
|
||||
tv_dict_clear(dict);
|
||||
|
||||
UIBridgeData *bridge = (UIBridgeData *)b;
|
||||
bool stopped = bridge->stopped = false;
|
||||
UI_BRIDGE_CALL(b, stop, 1, b);
|
||||
|
@@ -6,6 +6,7 @@ local eval = helpers.eval
|
||||
local meths = helpers.meths
|
||||
local request = helpers.request
|
||||
local pcall_err = helpers.pcall_err
|
||||
local command = helpers.command
|
||||
|
||||
describe('nvim_ui_attach()', function()
|
||||
before_each(function()
|
||||
@@ -34,4 +35,13 @@ describe('nvim_ui_attach()', function()
|
||||
eq('UI already attached to channel: 1',
|
||||
pcall_err(request, 'nvim_ui_attach', 40, 10, { rgb=false }))
|
||||
end)
|
||||
it('autocmds UIAttach/Detach set v:event', function()
|
||||
local screen = Screen.new()
|
||||
command('autocmd UIAttach * :let g:ui_attach_v_event = deepcopy(v:event)')
|
||||
command('autocmd UIDetach * :let g:ui_detach_v_event = deepcopy(v:event)')
|
||||
screen:attach()
|
||||
assert.same({chan=1}, eval('g:ui_attach_v_event'))
|
||||
screen:detach()
|
||||
assert.same({chan=1}, eval('g:ui_detach_v_event'))
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user