From e02a05e5fa50f21a6d4128582bf8a15141d6a763 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 18 Dec 2021 23:17:45 +0800 Subject: fix term mode --- xmake/core/base/tty.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'xmake/core/base/tty.lua') diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index 0417f9b8f..a744f12e0 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -24,6 +24,9 @@ local tty = tty or {} -- load modules local io = require("base/io") +-- save metatable and builtin functions +tty._term_mode = tty._term_mode or tty.term_mode + -- @see http://www.termsys.demon.co.uk/vtansi.htm -- write control characters @@ -392,5 +395,22 @@ function tty.has_color24() return has_color24 end +-- get term mode, e.g. stdin, stdout, stderr +-- +-- local oldmode = tty.term_mode(stdtype) +-- local oldmode = tty.term_mode(stdtype, newmode) +-- +function tty.term_mode(stdtype, newmode) + local oldmode = 0 + if stdtype == "stdin" then + oldmode = tty._term_mode(1, newmode) + elseif stdtype == "stdout" then + oldmode = tty._term_mode(2, newmode) + elseif stdtype == "stderr" then + oldmode = tty._term_mode(3, newmode) + end + return oldmode +end + -- return module return tty -- cgit v1.3.1