aboutsummaryrefslogtreecommitdiff
path: root/examples/compat.lua
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2024-05-06 11:44:47 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2024-05-20 12:43:55 +0200
commitdcd5d62501e61e0f6901d4d4687ab56430a4b8a7 (patch)
tree4501938052c0f62279eaae66c34811d4b5232fa2 /examples/compat.lua
parent1d64b5790f26760cb830336ccca9d51474b73ae8 (diff)
downloadluasystem-dcd5d62501e61e0f6901d4d4687ab56430a4b8a7.tar.gz
luasystem-dcd5d62501e61e0f6901d4d4687ab56430a4b8a7.tar.bz2
luasystem-dcd5d62501e61e0f6901d4d4687ab56430a4b8a7.zip
add example for reading a line from the terminal, non-blocking
Handles utf8, and character width
Diffstat (limited to 'examples/compat.lua')
-rw-r--r--examples/compat.lua5
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/compat.lua b/examples/compat.lua
index c00d44a..a59d964 100644
--- a/examples/compat.lua
+++ b/examples/compat.lua
@@ -5,12 +5,15 @@ local sys = require "system"
5 5
6 6
7 7
8if sys.is_windows then 8if sys.windows then
9 -- Windows holds multiple copies of environment variables, to ensure `getenv` 9 -- Windows holds multiple copies of environment variables, to ensure `getenv`
10 -- returns what `setenv` sets we need to use the `system.getenv` instead of 10 -- returns what `setenv` sets we need to use the `system.getenv` instead of
11 -- `os.getenv`. 11 -- `os.getenv`.
12 os.getenv = sys.getenv -- luacheck: ignore 12 os.getenv = sys.getenv -- luacheck: ignore
13 13
14 -- Set console output to UTF-8 encoding.
15 sys.setconsoleoutputcp(65001)
16
14 -- Set up the terminal to handle ANSI escape sequences on Windows. 17 -- Set up the terminal to handle ANSI escape sequences on Windows.
15 if sys.isatty(io.stdout) then 18 if sys.isatty(io.stdout) then
16 sys.setconsoleflags(io.stdout, sys.getconsoleflags(io.stdout) + sys.COF_VIRTUAL_TERMINAL_PROCESSING) 19 sys.setconsoleflags(io.stdout, sys.getconsoleflags(io.stdout) + sys.COF_VIRTUAL_TERMINAL_PROCESSING)