summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-31 22:11:16 +0800
committerruki <[email protected]>2020-05-31 22:11:16 +0800
commit0f6136ff2b2e43b60c11c265f990e9dd022d7a65 (patch)
tree76d2419b088c93baf704718ccf790e30aa494305
parent41bd7287e986fcf881c8d20494058c576bbcf252 (diff)
add some cursor ops for tty
-rw-r--r--xmake/core/base/tty.lua42
-rw-r--r--xmake/core/sandbox/modules/utils.lua4
2 files changed, 42 insertions, 4 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua
index d1245fc1a..7ad78ab3e 100644
--- a/xmake/core/base/tty.lua
+++ b/xmake/core/base/tty.lua
@@ -56,6 +56,48 @@ function tty.erase_line()
return tty
end
+-- erases the screen from the current line down to the bottom of the screen.
+function tty.erase_down()
+ tty._iowrite("\x1b[J")
+ return tty
+end
+
+-- erases the screen from the current line up to the top of the screen.
+function tty.erase_up()
+ tty._iowrite("\x1b[1J")
+ return tty
+end
+
+-- erases the screen with the background colour and moves the cursor to home.
+function tty.erase_screen()
+ tty._iowrite("\x1b[2J")
+ return tty
+end
+
+-- save current cursor position.
+function tty.cursor_save()
+ tty._iowrite("\x1b[s")
+ return tty
+end
+
+-- restores cursor position after a save cursor.
+function tty.cursor_restore()
+ tty._iowrite("\x1b[u")
+ return tty
+end
+
+-- save current cursor position and color attrs
+function tty.cursor_and_attrs_save()
+ tty._iowrite("\x1b7")
+ return tty
+end
+
+-- restores cursor position and color attrs after a save cursor.
+function tty.cursor_and_attrs_restore()
+ tty._iowrite("\x1b8")
+ return tty
+end
+
-- carriage return
function tty.cr()
tty._iowrite("\r")
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index 8492b1302..4dac4a91e 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -174,8 +174,6 @@ end
-- assert
function sandbox_utils.assert(value, format, ...)
-
- -- check
if not value then
if format ~= nil then
os.raiselevel(2, format, ...)
@@ -183,8 +181,6 @@ function sandbox_utils.assert(value, format, ...)
os.raiselevel(2, "assertion failed!")
end
end
-
- -- return it
return value
end