aboutsummaryrefslogtreecommitdiff
path: root/src/textadept.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/textadept.c')
-rw-r--r--src/textadept.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/textadept.c b/src/textadept.c
index a37471de..9a4a7e3b 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -1475,15 +1475,24 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) {
lua_pushboolean(L, 1), lua_setglobal(L, "WIN32");
#elif __OSX__
lua_pushboolean(L, 1), lua_setglobal(L, "OSX");
+#elif NCURSES
+ lua_pushboolean(L, 1), lua_setglobal(L, "NCURSES");
#endif
-#if GTK
const char *charset = 0;
+#if GTK
g_get_charset(&charset);
- lua_pushstring(L, charset), lua_setglobal(L, "_CHARSET");
#elif NCURSES
- lua_pushboolean(L, 1), lua_setglobal(L, "NCURSES");
- lua_pushstring(L, "UTF-8"), lua_setglobal(L, "_CHARSET"); // TODO: get charset
+ charset = getenv("CHARSET");
+ if (!charset || !*charset) {
+ char *locale = getenv("LC_ALL");
+ if (!locale || !*locale) locale = getenv("LANG");
+ if (locale && (charset = strchr(locale, '.'))) charset++;
+ }
+ // Note: __WIN32__ uses GetACP() to determine codepage.
+ // If __WIN32__ is ever supported, use a codepage -> charset look-up table
+ // like glib's `libcharset/localecharset.c`.
#endif
+ lua_pushstring(L, charset), lua_setglobal(L, "_CHARSET");
if (lL_dofile(L, "core/init.lua")) {
lua_getglobal(L, "_SCINTILLA");