From 4dd0fbac93fcd18a8074f5021ca60be4bb87e979 Mon Sep 17 00:00:00 2001 From: Thijs Date: Mon, 24 Jun 2024 23:18:10 +0200 Subject: enable Windows support requires LuaSystem to be installed --- README.md | 6 ++++++ term/init.lua | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 9ea4dd6..faf0194 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ zypper in lua-luaterm Adjust the repository URL to your version of openSUSE by substituting `openSUSE_Tumbleweed` with your actual version eg `opensSUSE_42.2`. +## Windows + +lua-term works on Windows as well when virtual terminal processing is enabled. To have this enabled automatically ensure that +[LuaSystem](https://github.com/lunarmodules/luasystem) is installed (version 0.4.0 or newer). If found, that module will be used +to enable virtual terminal processing and to switch output to utf-8. + Usage ----- diff --git a/term/init.lua b/term/init.lua index bd2024b..b0387a6 100644 --- a/term/init.lua +++ b/term/init.lua @@ -18,6 +18,19 @@ -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- THE SOFTWARE. +do -- set console to utf-8 and enable ANSI escape sequences on Windows + local ok, sys = pcall(require, "system") + if ok and sys.setconsoleflags and sys.windows then + sys.setconsoleoutputcp(sys.CODEPAGE_UTF8) + if sys.isatty(io.stdout) then + sys.setconsoleflags(io.stdout, sys.getconsoleflags(io.stdout) + sys.COF_VIRTUAL_TERMINAL_PROCESSING) + end + if sys.isatty(io.stderr) then + sys.setconsoleflags(io.stderr, sys.getconsoleflags(io.stderr) + sys.COF_VIRTUAL_TERMINAL_PROCESSING) + end + end +end + local term = require 'term.core' local sformat = string.format local iotype = io.type -- cgit v1.2.3-55-g6feb