aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-03-10 13:31:05 +0100
committerJustin M. Keyes <justinkz@gmail.com>2019-03-11 08:43:27 +0100
commit43184566aafdd3ed9e787775c83ba6b73faa0cf6 (patch)
tree217a2f72c6a74307153dbfe01b88da66c13ca513 /src
parentef5037e7f6e199ade4475d819842e66eb3bd8381 (diff)
downloadrneovim-43184566aafdd3ed9e787775c83ba6b73faa0cf6.tar.gz
rneovim-43184566aafdd3ed9e787775c83ba6b73faa0cf6.tar.bz2
rneovim-43184566aafdd3ed9e787775c83ba6b73faa0cf6.zip
TUI/background detection: hook into VimEnter event
If terminal response is received during startup, set 'background' from a nested "one-shot" (once) VimEnter autocmd. The previous not-so-clever "self-rescheduling" approach could cause a long delay at startup (event-loop does not make forward progress). fixes #9675 ref #9509
Diffstat (limited to 'src')
-rw-r--r--src/nvim/tui/input.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 3eb88366d6..703feac305 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -10,6 +10,7 @@
#include "nvim/charset.h"
#include "nvim/main.h"
#include "nvim/aucmd.h"
+#include "nvim/ex_docmd.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
@@ -357,15 +358,17 @@ static bool handle_forced_escape(TermInput *input)
static void set_bg_deferred(void **argv)
{
char *bgvalue = argv[0];
- if (starting) {
- // Wait until after startup, so OptionSet is triggered.
- loop_schedule(&main_loop, event_create(set_bg_deferred, 1, bgvalue));
- return;
- }
if (!option_was_set("bg") && !strequal((char *)p_bg, bgvalue)) {
// Value differs, apply it.
- set_option_value("bg", 0L, bgvalue, 0);
- reset_option_was_set("bg");
+ if (starting) {
+ // Wait until after startup, so OptionSet is triggered.
+ do_cmdline_cmd((bgvalue[0] == 'l')
+ ? "autocmd VimEnter * once nested set background=light"
+ : "autocmd VimEnter * once nested set background=dark");
+ } else {
+ set_option_value("bg", 0L, bgvalue, 0);
+ reset_option_was_set("bg");
+ }
}
}
@@ -424,7 +427,8 @@ static bool handle_background_color(TermInput *input)
double luminance = (0.299 * r) + (0.587 * g) + (0.114 * b); // CCIR 601
char *bgvalue = luminance < 0.5 ? "dark" : "light";
DLOG("bg response: %s", bgvalue);
- loop_schedule(&main_loop, event_create(set_bg_deferred, 1, bgvalue));
+ loop_schedule_deferred(&main_loop,
+ event_create(set_bg_deferred, 1, bgvalue));
} else {
DLOG("failed to parse bg response");
}