Raxol.Terminal.ANSI.CharacterSets (Raxol v0.2.0)

View Source

Manages character set switching and translation for the terminal emulator. Supports G0, G1, G2, G3 character sets and their switching operations.

Summary

Functions

Designates a character set for a specific G-set (G0-G3). gset_index is 0, 1, 2, or 3. charset_code is the character byte following ESC (, ESC ), ESC *, or ESC +.

Gets the active character set based on the current state.

Invokes a character set as the GL (left) character set. This is used by SI/SO (Shift In/Shift Out) control codes.

Creates a new character set state with default values.

Sets the GL (left) character set.

Sets the GR (right) character set.

Sets the single shift character set.

Switches the specified character set to the given charset.

Translates a character based on the active character set.

Translates a string using the current character set.

Types

charset()

@type charset() ::
  :us_ascii
  | :uk
  | :french
  | :german
  | :swedish
  | :swiss
  | :italian
  | :spanish
  | :portuguese
  | :japanese
  | :korean
  | :latin1
  | :latin2
  | :latin3
  | :latin4
  | :latin5
  | :latin6
  | :latin7
  | :latin8
  | :latin9
  | :latin10
  | :latin11
  | :latin12
  | :latin13
  | :latin14
  | :latin15

charset_state()

@type charset_state() :: %{
  g0: charset(),
  g1: charset(),
  g2: charset(),
  g3: charset(),
  gl: :g0 | :g1 | :g2 | :g3,
  gr: :g0 | :g1 | :g2 | :g3,
  single_shift: :g0 | :g1 | :g2 | :g3 | nil,
  locked_shift: boolean()
}

Functions

designate_charset(state, gset_index, charset_code)

@spec designate_charset(charset_state(), 0..3, byte()) :: charset_state()

Designates a character set for a specific G-set (G0-G3). gset_index is 0, 1, 2, or 3. charset_code is the character byte following ESC (, ESC ), ESC *, or ESC +.

get_active_charset(state)

@spec get_active_charset(charset_state()) :: charset()

Gets the active character set based on the current state.

invoke_charset(state, gset)

@spec invoke_charset(charset_state(), :g0 | :g1 | :g2 | :g3) :: charset_state()

Invokes a character set as the GL (left) character set. This is used by SI/SO (Shift In/Shift Out) control codes.

Examples

iex> state = Raxol.Terminal.ANSI.CharacterSets.new()
iex> state = Raxol.Terminal.ANSI.CharacterSets.switch_charset(state, :g1, :dec_special_graphics)
iex> state = Raxol.Terminal.ANSI.CharacterSets.invoke_charset(state, :g1)
iex> state.gl
:g1

new()

@spec new() :: %{
  g0: :us_ascii,
  g1: :us_ascii,
  g2: :us_ascii,
  g3: :us_ascii,
  gl: :g0,
  gr: :g1,
  single_shift: nil,
  locked_shift: false
}

Creates a new character set state with default values.

set_gl(state, set)

@spec set_gl(charset_state(), :g0 | :g1 | :g2 | :g3) :: charset_state()

Sets the GL (left) character set.

set_gr(state, set)

@spec set_gr(charset_state(), :g0 | :g1 | :g2 | :g3) :: charset_state()

Sets the GR (right) character set.

set_single_shift(state, set)

@spec set_single_shift(charset_state(), :g0 | :g1 | :g2 | :g3 | nil) ::
  charset_state()

Sets the single shift character set.

switch_charset(state, set, charset)

@spec switch_charset(charset_state(), :g0 | :g1 | :g2 | :g3, charset()) ::
  charset_state()

Switches the specified character set to the given charset.

translate_char(state, char)

@spec translate_char(charset_state(), char()) :: char()

Translates a character based on the active character set.

translate_string(state, string)

@spec translate_string(charset_state(), String.t()) :: String.t()

Translates a string using the current character set.