ExTermbox.Constants (ExTermbox v2.0.4)

View Source

Defines constants from the termbox2 library. These can be used e.g. to set formatting attributes, colors, input/output modes, or to identify keys passed in an event.

Values are based on termbox2 v2.5.0 (or compatible).

Summary

Functions

Retrieves an attribute constant by name

Retrieves the mapping of attribute constants (assuming 16-bit attributes).

Retrieves a color constant by name

Retrieves the mapping of color constants (basic 8 colors + default).

Retrieves an error code constant by name

Retrieves the mapping of error code constants.

Retrieves an event type constant by name

Retrieves the mapping of event type constants.

Retrieves the hide cursor constant.

Retrieves an input mode constant by name

Retrieves the mapping of input mode constants.

Retrieves a key constant by name

Retrieves the mapping of key constants for use with termbox2.

Retrieves a modifier constant by name

Retrieves the mapping of modifier constants.

Retrieves an output mode constant by name

Retrieves the mapping of output mode constants.

Resolves a color atom (e.g., :red) or integer to its integer value. Returns the default color value if the input is invalid or not found.

Types

attribute()

@type attribute() :: constant()

color()

@type color() :: constant()

constant()

@type constant() :: integer()

error_code()

@type error_code() :: constant()

event_type()

@type event_type() :: constant()

hide_cursor()

@type hide_cursor() :: constant()

input_mode()

@type input_mode() :: constant()

key()

@type key() :: constant()

modifier()

@type modifier() :: constant()

output_mode()

@type output_mode() :: constant()

Functions

attribute(name)

@spec attribute(atom()) :: attribute()

Retrieves an attribute constant by name

Examples

iex> attribute(:bold)
0x0100
iex> attribute(:underline)
0x0200
iex> attribute(:italic)
0x0800

attributes()

@spec attributes() :: %{required(atom()) => attribute()}

Retrieves the mapping of attribute constants (assuming 16-bit attributes).

color(name)

@spec color(atom()) :: color()

Retrieves a color constant by name

Examples

iex> color(:red)
0x02
iex> color(:blue)
0x05

colors()

@spec colors() :: %{required(atom()) => color()}

Retrieves the mapping of color constants (basic 8 colors + default).

error_code(name)

@spec error_code(atom()) :: error_code()

Retrieves an error code constant by name

Examples

iex> error_code(:unsupported_term)
-17
iex> error_code(:mem)
-5
iex> error_code(:ok)
0

error_codes()

@spec error_codes() :: %{required(atom()) => error_code()}

Retrieves the mapping of error code constants.

event_type(name)

@spec event_type(atom()) :: event_type()

Retrieves an event type constant by name

Examples

iex> event_type(:key)
0x01
iex> event_type(:resize)
0x02
iex> event_type(:mouse)
0x03

event_types()

@spec event_types() :: %{required(atom()) => event_type()}

Retrieves the mapping of event type constants.

hide_cursor()

@spec hide_cursor() :: hide_cursor()

Retrieves the hide cursor constant.

Examples

iex> hide_cursor()
-1

input_mode(name)

@spec input_mode(atom()) :: input_mode()

Retrieves an input mode constant by name

Examples

iex> input_mode(:esc)
1
iex> input_mode(:mouse)
4
iex> input_mode(:alt_with_mouse)
6

input_modes()

@spec input_modes() :: %{required(atom()) => input_mode()}

Retrieves the mapping of input mode constants.

key(name)

@spec key(atom()) :: key()

Retrieves a key constant by name

Examples

iex> key(:esc)
0x1B
iex> key(:space)
0x20
iex> key(:back_tab)
65513

keys()

@spec keys() :: %{required(atom()) => key()}

Retrieves the mapping of key constants for use with termbox2.

These are based on terminfo constants. Note that there's some overlap of terminfo values. For example, it's not possible to distinguish between <backspace> and ctrl-h.

mod(name)

@spec mod(atom()) :: modifier()

Retrieves a modifier constant by name

Examples

iex> mod(:alt)
1
iex> mod(:none)
0
iex> mod(:ctrl)
2
iex> mod(:motion)
8

modifiers()

@spec modifiers() :: %{required(atom()) => modifier()}

Retrieves the mapping of modifier constants.

output_mode(name)

@spec output_mode(atom()) :: output_mode()

Retrieves an output mode constant by name

Examples

iex> output_mode(:normal)
1
iex> output_mode(:term_256)
2
iex> output_mode(:truecolor)
5

output_modes()

@spec output_modes() :: %{required(atom()) => output_mode()}

Retrieves the mapping of output mode constants.

resolve_color(color_input)

@spec resolve_color(atom() | integer() | any()) :: integer()

Resolves a color atom (e.g., :red) or integer to its integer value. Returns the default color value if the input is invalid or not found.

This primarily works for the basic 8 colors defined in @colors. For extended color modes (256, truecolor, etc.), pass the integer directly. Attributes can also be passed as integers and will be returned as-is.