mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 04:28:33 +00:00
tui: make termkey use utf-8 mode when &encoding=utf-8 #2469
This commit is contained in:
@@ -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 */
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user