wezterm.format() function produces formatted strings with terminal graphic attributes such as bold, italic, colors, and underlines. The resulting string contains WezTerm-compatible escape sequences.
Signature
Parameters
FormatItem[]
required
An array of format items that define the text and its styling. Each item can be:
{Text="string"}- Text content to render{Foreground=color}- Set foreground color{Background=color}- Set background color{Attribute=attribute}- Set text attribute (bold, italic, underline)"ResetAttributes"- Reset all attributes to default
Return Value
string
A string with embedded escape sequences for the specified formatting
Format Items
Text
wezterm.format.
Foreground Color
Black, Maroon, Green, Olive, Navy, Purple, Teal, Silver, Grey, Red, Lime, Yellow, Blue, Fuchsia, Aqua, White
Background Color
Text Attributes
Underline
Intensity
Italic
Reset Attributes
Reset all attributes to their default values:Examples
Basic Colored Text
Bold and Colored
Underlined Text with Background
Status Bar with Date/Time
Multiple Styles
Custom Underline Color
You can use arbitrary escape sequences for advanced features like underline colors:Common Use Cases
Tab Title Formatting
Status Bar
Workspace Indicator
Log Messages
Color Specifications
Named Colors
You can use CSS color names:"red","blue","green","yellow", etc.
Hex Colors
Use standard hex format:"#ff0000"(red)"#00ff00"(green)"#0000ff"(blue)
ANSI Colors
Use the 16 standard ANSI colors (indices 0-15):- Black (0), Maroon (1), Green (2), Olive (3)
- Navy (4), Purple (5), Teal (6), Silver (7)
- Grey (8), Red (9), Lime (10), Yellow (11)
- Blue (12), Fuchsia (13), Aqua (14), White (15)
Performance Considerations
The
wezterm.format() function generates escape sequences at runtime. For frequently called event handlers (like update-status), consider caching formatted strings when possible.Related Functions
wezterm.log_info()- Log info messages (supports formatted strings)wezterm.log_warn()- Log warning messageswezterm.log_error()- Log error messageswindow:set_left_status()- Set left status bar contentwindow:set_right_status()- Set right status bar content
Source Reference
Implementation:lua-api-crates/termwiz-funcs/src/lib.rs:17,146-148