Raxol.Terminal.CharacterSets (Raxol v0.2.0)

View Source

Handles character set management and translation for the terminal emulator.

This module defines the character set state, including designated G0-G3 sets and active GL/GR sets. It also provides translation tables for different character sets and functions to translate characters based on the active set.

Summary

Functions

Invokes a designated character set as GL or GR. Handles SI (invokes G0 as GL), SO (invokes G1 as GL), ESC ~ (invokes G1 as GR), ESC } (invokes G2 as GR), ESC | (invokes G3 as GR). Updates the active_set based on the new GL mapping. Note: This implementation assumes basic SO/SI for GL. More complex shift functions (LS, SS) modify active_set differently.

Creates a new character set state with default values (US-ASCII).

Designates a character set for a specific target (G0-G3). target_set should be :g0, :g1, :g2, or :g3. charset is the atom representing the character set (e.g., :us_ascii, :dec_special_graphics).

Translates a codepoint based on the currently active character set in the state.

Types

charset_state()

@type charset_state() :: %Raxol.Terminal.CharacterSets{
  active_set: atom(),
  g_sets: %{g0: atom(), g1: atom(), g2: atom(), g3: atom()},
  gl: atom(),
  gr: atom()
}

Functions

invoke_designator(state, gset_atom)

@spec invoke_designator(charset_state(), atom()) :: charset_state()

Invokes a designated character set as GL or GR. Handles SI (invokes G0 as GL), SO (invokes G1 as GL), ESC ~ (invokes G1 as GR), ESC } (invokes G2 as GR), ESC | (invokes G3 as GR). Updates the active_set based on the new GL mapping. Note: This implementation assumes basic SO/SI for GL. More complex shift functions (LS, SS) modify active_set differently.

new()

@spec new() :: charset_state()

Creates a new character set state with default values (US-ASCII).

set_designator(state, target_set, charset)

@spec set_designator(charset_state(), atom(), atom()) :: charset_state()

Designates a character set for a specific target (G0-G3). target_set should be :g0, :g1, :g2, or :g3. charset is the atom representing the character set (e.g., :us_ascii, :dec_special_graphics).

translate_active(character_sets, codepoint)

@spec translate_active(charset_state(), non_neg_integer()) :: non_neg_integer()

Translates a codepoint based on the currently active character set in the state.