From 0e031e7908cdfcc8d41a3d6110ec07982c69d433 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Tue, 27 Feb 2024 10:07:18 +0900 Subject: [PATCH] rline: downstream locale fixes --- lib/rline.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/rline.c b/lib/rline.c index 8859b1d1..f0a369a2 100644 --- a/lib/rline.c +++ b/lib/rline.c @@ -560,7 +560,7 @@ static char * syn_krk_types[] = { "self", "super", /* implicit in a class method */ "len", "str", "int", "float", "dir", "repr", /* global functions from __builtins__ */ "list","dict","range", /* builtin classes */ - "object","exception","isinstance","type","tuple","reversed", + "object","isinstance","type","tuple","reversed", "print","set","any","all","bool","ord","chr","hex","oct","filter", "sorted","bytes","getattr","sum","min","max","id","hash","map","bin", "enumerate","zip","setattr","property","staticmethod","classmethod", @@ -2011,15 +2011,14 @@ static int handle_escape(int * this_buf, int * timeout, int c) { #ifndef _WIN32 static unsigned int _INTR, _EOF; static struct termios old; -static void get_initial_termios(void) { +static void set_unbuffered(void) { tcgetattr(STDOUT_FILENO, &old); _INTR = old.c_cc[VINTR]; _EOF = old.c_cc[VEOF]; -} -static void set_unbuffered(void) { struct termios new = old; new.c_lflag &= (~ICANON & ~ECHO & ~ISIG); tcsetattr(STDOUT_FILENO, TCSAFLUSH, &new); + if (wcwidth(0x3042) != 2) setlocale(LC_CTYPE, ""); } static void set_buffered(void) { @@ -2028,12 +2027,11 @@ static void set_buffered(void) { #else static unsigned int _INTR = 3; static unsigned int _EOF = 4; -static void get_initial_termios(void) { -} static void set_unbuffered(void) { /* Disables line input, echo, ^C processing, and a few others. */ SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_VIRTUAL_TERMINAL_INPUT); SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_WRAP_AT_EOL_OUTPUT); + setlocale(LC_CTYPE, "C.UTF-8"); } static void set_buffered(void) { /* These are the defaults */ @@ -2429,12 +2427,6 @@ static int read_line(void) { * Read a line of text with interactive editing. */ int rline(char * buffer, int buf_size) { -#ifndef _WIN32 - setlocale(LC_ALL, ""); -#else - setlocale(LC_ALL, "C.UTF-8"); -#endif - get_initial_termios(); set_unbuffered(); get_size();