diff options
| author | ruki <[email protected]> | 2025-10-27 14:17:54 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-27 14:17:54 +0800 |
| commit | 06dd715e91d3fed3b8101801eceda228c3ed4877 (patch) | |
| tree | 8c370783dd532b6cd8bec516af2644167ce22a4a /xmake/core/base/tty.lua | |
| parent | 954944d14d86d2ca4747887150a35b440864c03d (diff) | |
| parent | 988bc41fb22cdd7e4e005fc985576d46b2fe20d9 (diff) | |
Merge pull request #6970 from xmake-io/tty
Improve tty
Diffstat (limited to 'xmake/core/base/tty.lua')
| -rw-r--r-- | xmake/core/base/tty.lua | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua index 1e44c64bf..471fb355a 100644 --- a/xmake/core/base/tty.lua +++ b/xmake/core/base/tty.lua @@ -135,6 +135,90 @@ function tty.cursor_and_attrs_restore() return tty end +-- move cursor to absolute position (row, col) +-- row and col are 1-based (1, 1) is the top-left corner +function tty.cursor_move(row, col) + if tty.has_vtansi() then + row = row or 1 + col = col or 1 + if row > 0 and col > 0 then + tty._iowrite(string.format("\x1b[%d;%dH", row, col)) + end + end + return tty +end + +-- move cursor up by n lines +function tty.cursor_move_up(n) + if tty.has_vtansi() then + n = n or 1 + if n > 0 then + tty._iowrite(string.format("\x1b[%dA", n)) + end + end + return tty +end + +-- move cursor down by n lines +function tty.cursor_move_down(n) + if tty.has_vtansi() then + n = n or 1 + if n > 0 then + tty._iowrite(string.format("\x1b[%dB", n)) + end + end + return tty +end + +-- move cursor forward (right) by n columns +function tty.cursor_move_right(n) + if tty.has_vtansi() then + n = n or 1 + if n > 0 then + tty._iowrite(string.format("\x1b[%dC", n)) + end + end + return tty +end + +-- move cursor backward (left) by n columns +function tty.cursor_move_left(n) + if tty.has_vtansi() then + n = n or 1 + if n > 0 then + tty._iowrite(string.format("\x1b[%dD", n)) + end + end + return tty +end + +-- move cursor to specified column +function tty.cursor_move_to_col(col) + if tty.has_vtansi() then + col = col or 1 + if col > 0 then + tty._iowrite(string.format("\x1b[%dG", col)) + end + end + return tty +end + +-- hide cursor +function tty.cursor_hide() + if tty.has_vtansi() then + tty._iowrite("\x1b[?25l") + end + return tty +end + +-- show cursor +function tty.cursor_show() + if tty.has_vtansi() then + tty._iowrite("\x1b[?25h") + end + return tty +end + -- carriage return function tty.cr() tty._iowrite("\r") |
