41 lines
1.2 KiB
Text
41 lines
1.2 KiB
Text
include builtins\cffi.e
|
|
constant tGSH = """
|
|
HANDLE WINAPI GetStdHandle(
|
|
_In_ DWORD nStdHandle
|
|
);
|
|
""",
|
|
tSCOCP = """
|
|
BOOL WINAPI SetConsoleOutputCP(
|
|
_In_ UINT wCodePageID
|
|
);
|
|
""",
|
|
STD_OUTPUT_HANDLE = -11,
|
|
CP_UTF8 = 65001,
|
|
envset = {"LANG","LC_ALL","LC_CTYPE"}
|
|
|
|
atom k32 = NULL, xGetStdHandle, hConsole, xSetConsoleOutputCP
|
|
|
|
global function unicode_console()
|
|
-- initialises the windows console for unicode, and
|
|
-- returns true if unicode is supported, else false.
|
|
bool res = false
|
|
if platform()=WINDOWS then
|
|
if k32=NULL then
|
|
puts(1,"") -- force console to exist
|
|
k32 = open_dll("kernel32.dll")
|
|
xGetStdHandle = define_cffi_func(k32,tGSH)
|
|
hConsole = c_func(xGetStdHandle,{STD_OUTPUT_HANDLE})
|
|
xSetConsoleOutputCP = define_cffi_func(k32,tSCOCP)
|
|
end if
|
|
-- following is equivalent to running "chcp 65001":
|
|
res = c_func(xSetConsoleOutputCP,{CP_UTF8})
|
|
else -- LINUX
|
|
for i=1 to length(envset) do
|
|
if match("UTF",upper(getenv(envset[i])))!=0 then
|
|
res = true
|
|
exit
|
|
end if
|
|
end for
|
|
end if
|
|
return res
|
|
end function
|