summaryrefslogtreecommitdiff
path: root/xmake/core/base/tty.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-19 00:53:36 +0800
committerGitHub <[email protected]>2021-12-19 00:53:36 +0800
commitcbff24314b4fb76b2617f56d4f202389feb259fd (patch)
treeccfef243ae29218ea696315f7959d51feee92676 /xmake/core/base/tty.lua
parent7be1bc272914b757a4a7fe1792f7590de4a91cdf (diff)
parent2ab866f4457c9074255d0104b32fce420bb8b13e (diff)
Merge pull request #1926 from xmake-io/term_mode
fix term mode
Diffstat (limited to 'xmake/core/base/tty.lua')
-rw-r--r--xmake/core/base/tty.lua20
1 files changed, 20 insertions, 0 deletions
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