---
url: /api/scripts/extension-modules/core/base/tty.md
---
# core.base.tty

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.

## tty.erase\_line\_to\_end

* Erase from current cursor position to the end of the current line

#### Function Prototype

::: tip API

```lua
tty.erase_line_to_end()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.erase_line_to_end()
```

## tty.erase\_line\_to\_start

* Erase from current cursor position to the start of the current line

#### Function Prototype

::: tip API

```lua
tty.erase_line_to_start()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.erase_line_to_start()
```

## tty.erase\_line

* Erase the entire current line

#### Function Prototype

::: tip API

```lua
tty.erase_line()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.erase_line()
```

## tty.erase\_down

* Erase from current line down to the bottom of the screen

#### Function Prototype

::: tip API

```lua
tty.erase_down()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.erase_down()
```

## tty.erase\_up

* Erase from current line up to the top of the screen

#### Function Prototype

::: tip API

```lua
tty.erase_up()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.erase_up()
```

## tty.erase\_screen

* Erase the entire screen and move cursor to home position

#### Function Prototype

::: tip API

```lua
tty.erase_screen()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.erase_screen()
```

## tty.cursor\_save

* Save current cursor position

#### Function Prototype

::: tip API

```lua
tty.cursor_save()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_save()
```

## tty.cursor\_restore

* Restore saved cursor position

#### Function Prototype

::: tip API

```lua
tty.cursor_restore()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

-- Save cursor position
tty.cursor_save()

-- ... do something ...

-- Restore cursor position
tty.cursor_restore()
```

## tty.cursor\_and\_attrs\_save

* Save current cursor position and color attributes

#### Function Prototype

::: tip API

```lua
tty.cursor_and_attrs_save()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_and_attrs_save()
```

## tty.cursor\_and\_attrs\_restore

* Restore saved cursor position and color attributes

#### Function Prototype

::: tip API

```lua
tty.cursor_and_attrs_restore()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
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()
```

## tty.cr

* Carriage return

#### Function Prototype

::: tip API

```lua
tty.cr()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cr()
```

## tty.flush

* Flush terminal output

#### Function Prototype

::: tip API

```lua
tty.flush()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.flush()
```

## tty.shell

* Get shell name

#### Function Prototype

::: tip API

```lua
tty.shell()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| string | Returns the shell name (e.g., "bash", "zsh", "pwsh", "powershell", "cmd") |

#### Usage

```lua
import("core.base.tty")

local shell = tty.shell()
print("Current shell:", shell)  -- Output: "bash", "zsh", etc.
```

## tty.term

* Get terminal name

#### Function Prototype

::: tip API

```lua
tty.term()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| string | Returns the terminal name (e.g., "xterm", "vscode", "windows-terminal", "mintty") |

#### Usage

```lua
import("core.base.tty")

local term = tty.term()
print("Terminal:", term)  -- Output: "xterm", "vscode", etc.
```

## tty.session\_id

* Get terminal session ID

#### Function Prototype

::: tip API

```lua
tty.session_id()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| string | Returns the terminal session ID |

#### Usage

```lua
import("core.base.tty")

local session_id = tty.session_id()
print("Session ID:", session_id)
```

## tty.has\_emoji

* Check if terminal supports emoji

#### Function Prototype

::: tip API

```lua
tty.has_emoji()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| boolean | Returns true if emoji is supported, false otherwise |

#### Usage

```lua
import("core.base.tty")

if tty.has_emoji() then
    print("Emoji supported!")
else
    print("No emoji support")
end
```

## tty.has\_vtansi

* Check if terminal supports VT-ANSI sequences

#### Function Prototype

::: tip API

```lua
tty.has_vtansi()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| boolean | Returns true if VT-ANSI is supported, false otherwise |

#### Usage

```lua
import("core.base.tty")

if tty.has_vtansi() then
    -- Use advanced terminal features
    tty.erase_screen()
end
```

## tty.has\_color8

* Check if terminal supports 8 colors

#### Function Prototype

::: tip API

```lua
tty.has_color8()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| boolean | Returns true if 8 colors are supported, false otherwise |

#### Usage

```lua
import("core.base.tty")

if tty.has_color8() then
    -- Use 8-color escape sequences
end
```

## tty.has\_color256

* Check if terminal supports 256 colors

#### Function Prototype

::: tip API

```lua
tty.has_color256()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| boolean | Returns true if 256 colors are supported, false otherwise |

#### Usage

```lua
import("core.base.tty")

if tty.has_color256() then
    -- Use 256-color escape sequences
end
```

## tty.has\_color24

* Check if terminal supports 24-bit true color

#### Function Prototype

::: tip API

```lua
tty.has_color24()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| boolean | Returns true if 24-bit color is supported, false otherwise |

#### Usage

```lua
import("core.base.tty")

if tty.has_color24() then
    -- Use 24-bit true color escape sequences
end
```

## tty.term\_mode

* Get or set terminal mode

#### Function Prototype

::: tip API

```lua
tty.term_mode(stdtype: <string>, newmode?: <number>)
```

:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| stdtype | Required. Standard stream type ("stdin", "stdout", "stderr") |
| newmode | Optional. New terminal mode to set |

#### Return Value

| Type | Description |
|------|-------------|
| number | Returns the old terminal mode |

#### Usage

```lua
import("core.base.tty")

-- Get current mode
local oldmode = tty.term_mode("stdout")

-- Set new mode
tty.term_mode("stdout", newmode)
```

## tty.cursor\_move\_up&#x20;

* Move cursor up by n lines

#### Function Prototype

::: tip API

```lua
tty.cursor_move_up(n: <number>)
```

:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| n | Number of lines to move up |

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_move_up(3)  -- Move cursor up 3 lines
```

## tty.cursor\_move\_down&#x20;

* Move cursor down by n lines

#### Function Prototype

::: tip API

```lua
tty.cursor_move_down(n: <number>)
```

:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| n | Number of lines to move down |

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_move_down(2)  -- Move cursor down 2 lines
```

## tty.cursor\_move\_left&#x20;

* Move cursor left by n columns

#### Function Prototype

::: tip API

```lua
tty.cursor_move_left(n: <number>)
```

:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| n | Number of columns to move left |

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_move_left(5)  -- Move cursor left 5 columns
```

## tty.cursor\_move\_right&#x20;

* Move cursor right by n columns

#### Function Prototype

::: tip API

```lua
tty.cursor_move_right(n: <number>)
```

:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| n | Number of columns to move right |

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_move_right(10)  -- Move cursor right 10 columns
```

## tty.cursor\_move\_to\_col&#x20;

* Move cursor to specific column

#### Function Prototype

::: tip API

```lua
tty.cursor_move_to_col(n: <number>)
```

:::

#### Parameter Description

| Parameter | Description |
|-----------|-------------|
| n | Column number to move to (1-based) |

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_move_to_col(1)  -- Move cursor to start of line
```

## tty.cursor\_hide&#x20;

* Hide cursor

#### Function Prototype

::: tip API

```lua
tty.cursor_hide()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_hide()  -- Hide cursor
```

## tty.cursor\_show&#x20;

* Show cursor

#### Function Prototype

::: tip API

```lua
tty.cursor_show()
```

:::

#### Parameter Description

No parameters

#### Return Value

| Type | Description |
|------|-------------|
| tty | Returns the tty module for method chaining |

#### Usage

```lua
import("core.base.tty")

tty.cursor_show()  -- Show cursor
```
