summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-26 00:52:27 +0800
committerruki <[email protected]>2021-01-26 00:52:27 +0800
commit2bb2fac08d934d5611e2230948d6363a9dc581b2 (patch)
treec5517c85f7ea3e8a99a5a8dfa86ec5998efbd931
parent22e78e33f6c3567228a1b8b4e1837171498ccab3 (diff)
add tty.term
-rw-r--r--xmake/core/base/tty.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua
index 180232f50..e1b796f13 100644
--- a/xmake/core/base/tty.lua
+++ b/xmake/core/base/tty.lua
@@ -112,5 +112,83 @@ function tty.flush()
return tty
end
+-- get terminal name
+-- - xterm
+-- - cmd
+-- - vstudio (in visual studio)
+-- - vscode (in vscode)
+-- - msys2
+-- - cygwin
+-- - powershell
+-- - windows-terminal
+-- - gnome-terminal
+-- - xfce4-terminal
+-- - konsole
+-- - terminator
+-- - rxvt
+-- - lxterminal
+-- - unknown
+--
+function tty.term()
+ local term = tty._TERM
+ if term == nil then
+
+ -- get term from $TERM_PROGRAM
+ if term == nil then
+ local TERM_PROGRAM = os.getenv("TERM_PROGRAM")
+ if TERM_PROGRAM ~= nil then
+ if TERM_PROGRAM:find("vscode", 1, true) then
+ term = "vscode"
+ end
+ end
+ end
+
+ -- get term from system
+ if term == nil then
+ local subhost = xmake._SUBHOST
+ if subhost == "windows" then
+ if os.getenv("XMAKE_IN_VSTUDIO") then
+ term = "vstudio"
+ elseif os.getenv("WT_SESSION") then
+ term = "windows-terminal"
+ elseif os.getenv("PROMPT") then -- $PROMPT == "$P$G"
+ term = "cmd"
+ else
+ -- TODO maybe powershell if no $PROMPT, we need improve it
+ term = "powershell"
+ end
+ elseif subhost == "msys" then
+ term = "msys2"
+ elseif subhost == "cygwin" then
+ term = "cygwin"
+ elseif subhost == "macosx" then
+ term = "xterm"
+ end
+ end
+
+ -- get term from $TERM
+ if term == nil then
+ local TERM = os.getenv("TERM")
+ if TERM ~= nil then
+ if TERM:find("xterm", 1, true) then
+ term = "xterm"
+ end
+ end
+ end
+ tty._TERM = term or "unknown"
+ end
+ return term
+end
+
+-- has emoji?
+function tty.has_emoji()
+ local has_emoji = tty._HAS_EMOJI
+ if has_emoji == nil then
+ -- TODO
+ tty._HAS_EMOJI = has_emoji or false
+ end
+ return has_emoji
+end
+
-- return module
return tty