Repository navigation
Terminal Formatting
std::terminal adapts formatting to the current output capabilities.
color sets foreground color; bk_color sets the background. Both join their
text arguments with spaces and return a String.
Colors accept hex Strings such as "#31d8e0", comma-separated RGB Strings such as
"49,216,224", or [49, 216, 224]. True-color terminals receive RGB escapes;
256-color and basic-color terminals receive a nearest palette color.
Monochrome output receives plain text.
import std::terminal::{ color, bold }
echo (color "#31d8e0" "harbor" "open")
echo (bold "boarding")
harbor open
boarding
The displayed output above is from redirected, non-TTY output. bold, dim,
italic, underline, reverse, and strikethrough remain available on a
monochrome TTY but produce plain text when stdout is not a TTY.
$tty_color_mode has native type TtyColorMode, with variants
TtyMonochrome, TtyBasic, Tty256, and TtyTrueColor. The interpreter initializes
it for the current terminal. Prefer the formatting helpers to manually choosing
escape sequences for every branch.
-
term_sizereturns[rows, columns] | (). -
cursor_positionreturns[row, column] | (). -
move_cursor row columnwrites a movement immediately. -
clearreturns the clear-screen/home sequence.
Cursor coordinates are one based, matching terminal escape conventions.
Array positions in Shelly remain zero based. Unavailable queries return ();
movement and clearing do nothing when output is not a TTY.
Terminal queries can require a foreground terminal. Check the optional result before destructuring it. Use the line-editing API when Reedline should own repainting and cursor positioning during interactive input.
Related: Prompts · Line editing · Environment
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use