Raxol.Terminal.Commands.Parser (Raxol v0.3.0)
View SourceHandles parsing of command parameters in terminal sequences.
This module is part of the terminal command execution system. It provides utilities for parsing and extracting parameters from CSI, OSC, and DCS sequence parameter strings.
Summary
Functions
Gets a parameter at a specific index from the params list.
Safely parses a string into an integer.
Parses a raw parameter string buffer into a list of integers or nil values.
Functions
@spec get_param([integer() | nil], non_neg_integer(), integer()) :: integer()
Gets a parameter at a specific index from the params list.
If the parameter is not available, returns the provided default value.
Examples
iex> Parser.get_param([5, 10, 15], 2)
10
iex> Parser.get_param([5, 10], 3)
1
iex> Parser.get_param([5, 10], 3, 0)
0
Safely parses a string into an integer.
Returns the parsed integer, or nil on failure.
Examples
iex> Parser.parse_int("123")
123
iex> Parser.parse_int("abc")
nil
Parses a raw parameter string buffer into a list of integers or nil values.
Handles empty or malformed parameters by converting them to nil. Handles parameters with sub-parameters (separated by ':')
Examples
iex> Parser.parse_params("5;10;15")
[5, 10, 15]
iex> Parser.parse_params("5;10;;15")
[5, 10, nil, 15]
iex> Parser.parse_params("5:1;10:2;15:3")
[[5, 1], [10, 2], [15, 3]]