diff options
| author | ruki <[email protected]> | 2020-05-31 21:43:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-31 21:43:47 +0800 |
| commit | 41bd7287e986fcf881c8d20494058c576bbcf252 (patch) | |
| tree | 49d6b3d7082d87d37ff656ace7a0cd710245fda6 /xmake/core/base/tty.lua | |
| parent | 3c1d11faa2ca0c6e6eb1664ee938d5c49867b02d (diff) | |
add tty and replace clearline
Diffstat (limited to 'xmake/core/base/tty.lua')
| -rw-r--r-- | xmake/core/base/tty.lua | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua new file mode 100644 index 000000000..d1245fc1a --- /dev/null +++ b/xmake/core/base/tty.lua @@ -0,0 +1,74 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file tty.lua +-- + +-- define module +local tty = tty or {} + +-- load modules +local io = require("base/io") + +-- @see http://www.termsys.demon.co.uk/vtansi.htm + +-- write control characters +function tty._iowrite(...) + local isatty = tty._ISATTY + if isatty == nil then + isatty = io.isatty() + tty._ISATTY = isatty + end + if isatty then + io.write(...) + end +end + +-- erases from the current cursor position to the end of the current line. +function tty.erase_line_to_end() + tty._iowrite("\x1b[K") + return tty +end + +-- erases from the current cursor position to the start of the current line. +function tty.erase_line_to_start() + tty._iowrite("\x1b[1K") + return tty +end + +-- erases the entire current line +function tty.erase_line() + tty._iowrite("\x1b[2K") + return tty +end + +-- carriage return +function tty.cr() + tty._iowrite("\r") + return tty +end + +-- flush control +function tty.flush() + if io.isatty() then + io.flush() + end + return tty +end + +-- return module +return tty |
