TermUI.Capabilities.Fallbacks (TermUI v0.2.0)
View SourceGraceful degradation utilities for terminal capabilities.
Provides fallback chains for:
- Colors: true-color → 256-color → 16-color → monochrome
- Characters: Unicode box-drawing → ASCII art
Summary
Functions
Converts a 256-color index to the nearest 16-color ANSI index.
Returns the appropriate color based on terminal capabilities.
Converts an RGB color to the nearest 16-color ANSI index.
Converts an RGB color to the nearest 256-color palette index.
Converts a string containing Unicode to ASCII-safe version.
Converts a Unicode character to its ASCII fallback.
Functions
@spec color_256_to_16(0..255) :: 0..15
Converts a 256-color index to the nearest 16-color ANSI index.
Returns an integer 0-15.
@spec degrade_color( non_neg_integer(), non_neg_integer(), non_neg_integer(), TermUI.Capabilities.color_mode() ) :: {:rgb, non_neg_integer(), non_neg_integer(), non_neg_integer()} | {:index_256, 0..255} | {:index_16, 0..15} | :none
Returns the appropriate color based on terminal capabilities.
Automatically degrades RGB to 256 to 16 based on capability.
@spec rgb_to_16(non_neg_integer(), non_neg_integer(), non_neg_integer()) :: 0..15
Converts an RGB color to the nearest 16-color ANSI index.
Returns an integer 0-15.
@spec rgb_to_256(non_neg_integer(), non_neg_integer(), non_neg_integer()) :: 0..255
Converts an RGB color to the nearest 256-color palette index.
Returns an integer 0-255.
Converts a string containing Unicode to ASCII-safe version.
Replaces all known Unicode characters with their ASCII fallbacks.
Converts a Unicode character to its ASCII fallback.
Returns the original character if no fallback is defined.