diff options
-rw-r--r-- | src/nvim/option.c | 5 | ||||
-rw-r--r-- | src/nvim/tui/term_input.inl | 21 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 7 | ||||
-rw-r--r-- | src/nvim/ui.c | 6 | ||||
-rw-r--r-- | src/nvim/ui.h | 1 |
5 files changed, 26 insertions, 14 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index a5ef6b6e7e..6b91224987 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3710,6 +3710,7 @@ did_set_string_option ( ml_setflags(curbuf); } } + if (errmsg == NULL) { /* canonize the value, so that STRCMP() can be used on it */ p = enc_canonize(*varp); @@ -3721,13 +3722,15 @@ did_set_string_option ( } } - if (errmsg == NULL) { /* When 'keymap' is used and 'encoding' changes, reload the keymap * (with another encoding). */ if (varp == &p_enc && *curbuf->b_p_keymap != NUL) (void)keymap_init(); + if (varp == &p_enc) { + ui_update_encoding(); + } } } else if (varp == &p_penc) { /* Canonize printencoding if VIM standard one */ diff --git a/src/nvim/tui/term_input.inl b/src/nvim/tui/term_input.inl index 544fe8b12c..d25cbb7ba1 100644 --- a/src/nvim/tui/term_input.inl +++ b/src/nvim/tui/term_input.inl @@ -257,23 +257,11 @@ static TermInput *term_input_new(void) rv->paste_enabled = false; rv->in_fd = 0; - // Set terminal encoding based on environment(taken from libtermkey source - // code) - const char *e; - int flags = 0; - if (((e = os_getenv("LANG")) || (e = os_getenv("LC_MESSAGES")) - || (e = os_getenv("LC_ALL"))) && (e = strchr(e, '.')) && e++ && - (strcasecmp(e, "UTF-8") == 0 || strcasecmp(e, "UTF8") == 0)) { - flags |= TERMKEY_FLAG_UTF8; - } else { - flags |= TERMKEY_FLAG_RAW; - } - const char *term = os_getenv("TERM"); if (!term) { term = ""; // termkey_new_abstract assumes non-null (#2745) } - rv->tk = termkey_new_abstract(term, flags); + rv->tk = termkey_new_abstract(term, 0); int curflags = termkey_get_canonflags(rv->tk); termkey_set_canonflags(rv->tk, curflags | TERMKEY_CANON_DELBS); // setup input handle @@ -302,3 +290,10 @@ static void term_input_destroy(TermInput *input) event_poll(0); // Run once to remove references to input/timer handles xfree(input); } + +static void term_input_set_encoding(TermInput *input, char* enc) +{ + int enc_flag = strcmp(enc, "utf-8") == 0 ? TERMKEY_FLAG_UTF8 + : TERMKEY_FLAG_RAW; + termkey_set_flags(input->tk, enc_flag); +} diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 7df1c4f381..fe29dbd961 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -161,6 +161,7 @@ UI *tui_start(void) ui->suspend = tui_suspend; ui->set_title = tui_set_title; ui->set_icon = tui_set_icon; + ui->set_encoding = tui_set_encoding; // Attach ui_attach(ui); return ui; @@ -592,6 +593,12 @@ static void tui_set_icon(UI *ui, char *icon) { } +static void tui_set_encoding(UI *ui, char* enc) +{ + TUIData *data = ui->data; + term_input_set_encoding(data->input, enc); +} + static void invalidate(UI *ui, int top, int bot, int left, int right) { TUIData *data = ui->data; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index e22ef6692d..088055777a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -113,6 +113,11 @@ void ui_set_icon(char *icon) UI_CALL(flush); } +void ui_update_encoding(void) +{ + UI_CALL(set_encoding, (char*)p_enc); +} + // May update the shape of the cursor. void ui_cursor_shape(void) { @@ -183,6 +188,7 @@ void ui_attach(UI *ui) } uis[ui_count++] = ui; + ui_update_encoding(); ui_refresh(); } diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 71ed9b3097..76ceec7775 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -38,6 +38,7 @@ struct ui_t { void (*suspend)(UI *ui); void (*set_title)(UI *ui, char *title); void (*set_icon)(UI *ui, char *icon); + void (*set_encoding)(UI *ui, char *enc); void (*stop)(UI *ui); }; |