This module provides terminal control and detection capabilities for terminal operations.
::: tip TIP
To use this module, you need to import it first: import("core.base.tty")
:::
This module provides functions for terminal control sequences, color support detection, and terminal information querying. It supports VT-ANSI sequences for advanced terminal manipulation.
::: tip API
tty.erase_line_to_end()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.erase_line_to_end()
::: tip API
tty.erase_line_to_start()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.erase_line_to_start()
::: tip API
tty.erase_line()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.erase_line()
::: tip API
tty.erase_down()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.erase_down()
::: tip API
tty.erase_up()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.erase_up()
::: tip API
tty.erase_screen()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.erase_screen()
::: tip API
tty.cursor_save()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_save()
::: tip API
tty.cursor_restore()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
-- Save cursor position
tty.cursor_save()
-- ... do something ...
-- Restore cursor position
tty.cursor_restore()
::: tip API
tty.cursor_and_attrs_save()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_and_attrs_save()
::: tip API
tty.cursor_and_attrs_restore()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
-- Save cursor and attributes
tty.cursor_and_attrs_save()
-- ... change colors, do something ...
-- Restore cursor position and colors
tty.cursor_and_attrs_restore()
::: tip API
tty.cr()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cr()
::: tip API
tty.flush()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.flush()
::: tip API
tty.shell()
:::
No parameters
| Type | Description |
|---|---|
| string | Returns the shell name (e.g., "bash", "zsh", "pwsh", "powershell", "cmd") |
import("core.base.tty")
local shell = tty.shell()
print("Current shell:", shell) -- Output: "bash", "zsh", etc.
::: tip API
tty.term()
:::
No parameters
| Type | Description |
|---|---|
| string | Returns the terminal name (e.g., "xterm", "vscode", "windows-terminal", "mintty") |
import("core.base.tty")
local term = tty.term()
print("Terminal:", term) -- Output: "xterm", "vscode", etc.
::: tip API
tty.session_id()
:::
No parameters
| Type | Description |
|---|---|
| string | Returns the terminal session ID |
import("core.base.tty")
local session_id = tty.session_id()
print("Session ID:", session_id)
::: tip API
tty.has_emoji()
:::
No parameters
| Type | Description |
|---|---|
| boolean | Returns true if emoji is supported, false otherwise |
import("core.base.tty")
if tty.has_emoji() then
print("Emoji supported!")
else
print("No emoji support")
end
::: tip API
tty.has_vtansi()
:::
No parameters
| Type | Description |
|---|---|
| boolean | Returns true if VT-ANSI is supported, false otherwise |
import("core.base.tty")
if tty.has_vtansi() then
-- Use advanced terminal features
tty.erase_screen()
end
::: tip API
tty.has_color8()
:::
No parameters
| Type | Description |
|---|---|
| boolean | Returns true if 8 colors are supported, false otherwise |
import("core.base.tty")
if tty.has_color8() then
-- Use 8-color escape sequences
end
::: tip API
tty.has_color256()
:::
No parameters
| Type | Description |
|---|---|
| boolean | Returns true if 256 colors are supported, false otherwise |
import("core.base.tty")
if tty.has_color256() then
-- Use 256-color escape sequences
end
::: tip API
tty.has_color24()
:::
No parameters
| Type | Description |
|---|---|
| boolean | Returns true if 24-bit color is supported, false otherwise |
import("core.base.tty")
if tty.has_color24() then
-- Use 24-bit true color escape sequences
end
::: tip API
tty.term_mode(stdtype: <string>, newmode?: <number>)
:::
| Parameter | Description |
|---|---|
| stdtype | Required. Standard stream type ("stdin", "stdout", "stderr") |
| newmode | Optional. New terminal mode to set |
| Type | Description |
|---|---|
| number | Returns the old terminal mode |
import("core.base.tty")
-- Get current mode
local oldmode = tty.term_mode("stdout")
-- Set new mode
tty.term_mode("stdout", newmode)
::: tip API
tty.cursor_move_up(n: <number>)
:::
| Parameter | Description |
|---|---|
| n | Number of lines to move up |
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_move_up(3) -- Move cursor up 3 lines
::: tip API
tty.cursor_move_down(n: <number>)
:::
| Parameter | Description |
|---|---|
| n | Number of lines to move down |
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_move_down(2) -- Move cursor down 2 lines
::: tip API
tty.cursor_move_left(n: <number>)
:::
| Parameter | Description |
|---|---|
| n | Number of columns to move left |
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_move_left(5) -- Move cursor left 5 columns
::: tip API
tty.cursor_move_right(n: <number>)
:::
| Parameter | Description |
|---|---|
| n | Number of columns to move right |
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_move_right(10) -- Move cursor right 10 columns
::: tip API
tty.cursor_move_to_col(n: <number>)
:::
| Parameter | Description |
|---|---|
| n | Column number to move to (1-based) |
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_move_to_col(1) -- Move cursor to start of line
::: tip API
tty.cursor_hide()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_hide() -- Hide cursor
::: tip API
tty.cursor_show()
:::
No parameters
| Type | Description |
|---|---|
| tty | Returns the tty module for method chaining |
import("core.base.tty")
tty.cursor_show() -- Show cursor