module Terminal

Extended Modules

Defined in:

styles.cr
terminal.cr

Constant Summary

OSC8_TERMS = ["xterm-kitty", "kitty", "alacritty", "foot", "wezterm", "ghostty", "contour"]

Terminals whose TERM is known to support OSC 8 hyperlinks.

Instance Method Summary

Instance Method Detail

def display_width(text : String) : Int32 #

Display width of a string in terminal columns: East Asian Wide/Fullwidth codepoints count 2 columns, combining marks and variation selectors count 0, everything else 1. Wrapping and table sizing need this because a codepoint count mis-measures wide glyphs.


[View source]
def highlight(source : String, language : String, theme : String | Nil) : String #

[View source]
def osc8_capable? : Bool #

OSC 8 support judged from the environment alone, so it can be asked about (and tested) without a terminal attached.


[View source]
def parse_color(color) : Array(Int32) | Nil #

Parse an X11-style color reply like "rgb:1c1c/1c1c/1c1c" into [red, green, blue], or nil if it doesn't parse


[View source]
def query_terminal(color) : String #

Query a terminal color via OSC and read the reply. If the terminal never replies (some don't support the query), time out instead of blocking forever.


[View source]
def show_image(path : String) : String #

[View source]
def supports_images? : Bool #

[View source]
def supports_links? : Bool #

[View source]
def terminal_light? : Bool #

[View source]
def terminal_width : Int32 | Nil #

Get terminal width, with fallback Returns nil if not in a TTY or unable to determine


[View source]
def theme(name : String | Nil = nil) : Hash(String, Style) #

[View source]