Capability detection
Functions for detecting terminal capabilities and properties.terminal::is_tty()
Check if stdout is a terminal.terminal::is_tty::stdin()
Check if stdin is a terminal.terminal::is_tty::stderr()
Check if stderr is a terminal.terminal::width()
Get terminal width in columns.terminal::height()
Get terminal height in rows.terminal::size()
Get both width and height as space-separated values.terminal::has_colour()
Check if terminal supports colours (at least 8 colours).terminal::has_256colour()
Check if terminal supports 256 colours.terminal::has_truecolour()
Check if terminal supports true colour (24-bit RGB).terminal::name()
Return the terminal emulator name if detectable.$TERM_PROGRAM, $TERMINAL, or $TERM (defaults to “unknown”).
Cursor control
Functions for controlling cursor visibility and position.Cursor visibility functions
Cursor visibility functions
Cursor position functions
Cursor position functions
terminal::cursor::save()
Save current cursor position.\033[sterminal::cursor::restore()
Restore cursor to saved position.Escape sequence:\033[uterminal::cursor::move()
Move cursor to specific row and column (1-indexed).$1- Row number (1-indexed)$2- Column number (1-indexed)
\033[row;colHterminal::cursor::home()
Move cursor to top-left corner (1,1).\033[HRelative cursor movement
Relative cursor movement
terminal::cursor::up()
Move cursor up by n rows (default 1).$1- Number of rows (default: 1)
\033[nAterminal::cursor::down()
Move cursor down by n rows (default 1).$1- Number of rows (default: 1)
\033[nBterminal::cursor::right()
Move cursor right by n columns (default 1).$1- Number of columns (default: 1)
\033[nCterminal::cursor::left()
Move cursor left by n columns (default 1).$1- Number of columns (default: 1)
\033[nDterminal::cursor::next_line()
Move cursor to start of line n lines down (default 1).$1- Number of lines (default: 1)
\033[nEterminal::cursor::prev_line()
Move cursor to start of line n lines up (default 1).$1- Number of lines (default: 1)
\033[nFterminal::cursor::col()
Move cursor to specific column on current line (1-indexed).$1- Column number (default: 1)
\033[nGScreen manipulation
Functions for clearing, scrolling, and managing screen buffers.Screen clearing functions
Screen clearing functions
terminal::clear()
Clear entire screen and move cursor to home position.\033[2J followed by \033[Hterminal::clear::to_end()
Clear from cursor to end of screen.\033[0Jterminal::clear::to_start()
Clear from cursor to beginning of screen.\033[1Jterminal::clear::line()
Clear current line.\033[2Kterminal::clear::line_end()
Clear from cursor to end of line.\033[0Kterminal::clear::line_start()
Clear from cursor to start of line.\033[1KAlternate screen buffer
Alternate screen buffer
terminal::screen::alternate()
Enter alternate screen buffer (like vim/less).\033[?1049hterminal::screen::normal()
Return to normal screen buffer.Escape sequence:\033[?1049lterminal::screen::wrap()
Run a command in alternate screen buffer, then return to normal.$@- Command and arguments to execute
terminal::screen::alternate_enter()
Enter alternate screen with cleanup trap. Automatically sets up trap to return to normal screen on EXIT/INT/TERM.terminal::screen::alternate_exit()
Exit alternate screen and remove traps.Scrolling and other functions
Scrolling and other functions
terminal::scroll::up()
Scroll screen up by n lines (default 1).$1- Number of lines (default: 1)
\033[nSterminal::scroll::down()
Scroll screen down by n lines (default 1).$1- Number of lines (default: 1)
\033[nTterminal::title()
Set terminal window title (works in most modern terminal emulators).$1- Title text
\033]0;title\007terminal::bell()
Ring the terminal bell.\007Input handling
Functions for reading keyboard input and managing terminal echo.Key reading functions
Key reading functions
terminal::read_key()
Read a single keypress without requiring Enter.$1- Variable name to store key (default:_TERMINAL_KEY)
terminal::read_key::timeout()
Read a single keypress with timeout.$1- Variable name to store key (default:_TERMINAL_KEY)$2- Timeout in seconds (default: 5)
Confirmation prompts
Confirmation prompts
terminal::confirm()
Prompt user for yes/no confirmation. Returns 0 for yes, 1 for no.$1- Prompt text (default: “Are you sure?”)
terminal::confirm::default()
Prompt with a default choice shown. Empty input uses the default.$1- Default choice: “yes” or “no”$2- Prompt text (default: “Are you sure?”)
Echo control and password input
Echo control and password input
Shell options (shopt)
Functions for managing bash shell options.General shopt functions
General shopt functions
terminal::shopt::enable()
Enable a shopt option.$1- Option name
terminal::shopt::disable()
Disable a shopt option.$1- Option name
terminal::shopt::is_enabled()
Check if a shopt option is enabled.$1- Option name
terminal::shopt::get()
Get current value of a shopt option (“on” or “off”).$1- Option name
terminal::shopt::list::enabled()
List all enabled shopt options.terminal::shopt::list::disabled()
List all disabled shopt options.terminal::shopt::save()
Save current shopt state as restore commands.terminal::shopt::load()
Restore shopt state from a variable.$1- Variable name containing saved state (default:_SHOPT_STATE)
Common shopt convenience toggles
Common shopt convenience toggles
These functions provide quick enable/disable for commonly used shell options.Globstar (
Nocasematch (case-insensitive