Jump to content

Terminal control/Unicode output: Difference between revisions

m
(Added Seed7 example)
Line 386:
Works on both linux and windows.
 
First,The hide some of thefollowing (grubby low-level details are hidden away in) abuiltins/unicode_console.e re-usablewhich is now included in the standard includedistribution:
<lang Phix>--include builtins\cffi.e
constant tGSH = """
-- builtins/unicode_console.e
--
-- Implements unicode_console() -- initialises one, and returns true if supported
--
-- While there is some appeal to performing (the equivalent inline assembly of) this automatically in the
-- back-end/run-time, it would probably break too much legacy code that assumes Windows-1252 or ISO-8859.
--
include builtins\cffi.e
--set_unicode(true)
constant
--windows:
tGSH = """
HANDLE WINAPI GetStdHandle(
_In_ DWORD nStdHandle
Line 411 ⟶ 400:
STD_OUTPUT_HANDLE = -11,
CP_UTF8 = 65001,
--linux:
envset = {"LANG","LC_ALL","LC_CTYPE"}
 
atom k32 = NULL, xGetStdHandle, hConsole, xSetConsoleOutputCP
xGetStdHandle,
hConsole,
xSetConsoleOutputCP
 
global function unicode_console()
-- initialises the windows console for unicode, and
-- and returns true/false if unicode is supported, else false.
bool res = false
if platform()=WINDOWS then
Line 431 ⟶ 416:
xSetConsoleOutputCP = define_cffi_func(k32,tSCOCP)
end if
-- the following is equivalent to running "chcp 65001":
res = c_func(xSetConsoleOutputCP,{CP_UTF8})
-- zero(false) means failure.
else -- LINUX
for i=1 to length(envset) do
Line 444 ⟶ 428:
return res
end function</lang>
WeWhich can thenbe use itused like this:
That file has now been added to the standard distribution build files (0.8.0 and later, not yet uploaded)
 
We can then use it like this:
<lang Phix>include builtins\unicode_console.e
 
7,806

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.