Raxol.Terminal.Rendering.LigatureRenderer (Raxol v2.0.1)
View SourceProgramming font ligature rendering system for Raxol terminals.
This module provides comprehensive support for programming font ligatures with:
- Multi-character ligature detection and replacement
- Font-specific ligature mapping (FiraCode, JetBrains Mono, Cascadia Code, etc.)
- Unicode rendering with proper character width calculation
- Performance-optimized ligature processing
- Customizable ligature sets and user preferences
- Fallback handling for non-ligature fonts
Supported Ligatures
Arrows and Flow
->,<-,=>,<=,>=,!=,==,===|>,<|,>>,<<,<>,<=>,<->~>,<~,~>>,<<~,<~~,~~>
Programming Symbols
++,--,**,//,::,;;,??,!!&&,||,&&&,|||#=,#!,#?,#_,##/*,*/,/**,**/
Mathematical
<=,>=,!=,==,===,!==<<=,>>=,<=>,<->+-,-+,*=,/=,%=,^=
Usage
# Configure ligature rendering
config = LigatureRenderer.config(
font: :fira_code,
enabled_sets: [:arrows, :programming, :math],
disabled_ligatures: ["->"] # Disable specific ligatures
)
# Render text with ligatures
text = "const arrow = (x) => x + 1; // Lambda function"
rendered = LigatureRenderer.render(text, config)
# Check if text contains ligatures
has_ligatures? = LigatureRenderer.contains_ligatures?(text, config)
Summary
Functions
Gets all available ligatures for a specific font and configuration.
Creates a ligature rendering configuration.
Checks if text contains any ligatures that would be rendered.
Gets cursor position mapping after ligature rendering.
Detects font ligature capabilities.
Converts ligature unicode points back to original text sequences.
Optimizes ligature configuration for performance.
Gets performance statistics for ligature rendering.
Renders text with ligatures applied.
Converts text to a ligature-aware representation for processing.
Validates ligature configuration.
Calculates the visual width of text after ligature rendering.
Types
@type font_family() ::
:fira_code | :jetbrains_mono | :cascadia_code | :iosevka | :hack | :custom
@type ligature_config() :: %Raxol.Terminal.Rendering.LigatureRenderer{ custom_ligatures: %{required(String.t()) => unicode_point()}, disabled_ligatures: [String.t()], enabled_sets: [ligature_set()], fallback_enabled: boolean(), font: font_family(), performance_mode: boolean() }
@type ligature_set() ::
:arrows | :programming | :math | :brackets | :comments | :operators
@type unicode_point() :: 0..1_114_111
Functions
Gets all available ligatures for a specific font and configuration.
Examples
config = LigatureRenderer.config(font: :fira_code)
ligatures = LigatureRenderer.available_ligatures(config)
Creates a ligature rendering configuration.
Examples
config = LigatureRenderer.config(
font: :fira_code,
enabled_sets: [:arrows, :programming],
disabled_ligatures: ["->", "<="]
)
Checks if text contains any ligatures that would be rendered.
Examples
config = LigatureRenderer.config()
LigatureRenderer.contains_ligatures?("hello -> world", config)
# true
LigatureRenderer.contains_ligatures?("hello world", config)
# false
Gets cursor position mapping after ligature rendering.
When ligatures are rendered, cursor positions need to be adjusted because multiple characters may render as one.
Detects font ligature capabilities.
Attempts to determine if the current terminal font supports ligatures.
Converts ligature unicode points back to original text sequences.
Useful for editing operations where you need the original text.
Optimizes ligature configuration for performance.
Analyzes text patterns to suggest optimal ligature sets.
Gets performance statistics for ligature rendering.
Renders text with ligatures applied.
Examples
config = LigatureRenderer.config(font: :fira_code)
text = "const sum = (a, b) => a + b;"
rendered = LigatureRenderer.render(text, config)
Converts text to a ligature-aware representation for processing.
This creates a structure that maintains both original text and ligature information for complex text operations.
Validates ligature configuration.
Calculates the visual width of text after ligature rendering.
Some ligatures reduce the visual width (e.g., "->" becomes one character), which is important for proper text alignment and cursor positioning.