Raxol.Core.Accessibility (Raxol v0.4.0)

View Source

Accessibility module for Raxol terminal UI applications.

This module provides accessibility features including:

  • Screen reader announcements
  • Keyboard navigation enhancements
  • High contrast mode
  • Reduced motion support
  • Focus management
  • Large text support

Usage

# Enable accessibility features
Accessibility.enable()

# Make an announcement for screen readers
Accessibility.announce("You have selected the search button")

# Enable high contrast mode
Accessibility.set_high_contrast(true)

# Enable reduced motion mode
Accessibility.set_reduced_motion(true)

# Enable large text mode
Accessibility.set_large_text(true)

Summary

Functions

Make an announcement for screen readers.

Clear all pending announcements.

Gets the current color scheme.

Disable accessibility features.

Enable accessibility features with the given options.

Gets the current font size multiplier.

Get the current color scheme based on accessibility settings.

Get style settings for a component type.

Get metadata for an element.

Get the next announcement to be read by screen readers.

Gets an accessibility option value.

Get the current text scale factor based on the large text setting.

Register style settings for a component type.

Register metadata for an element to be used for accessibility features.

Checks if screen reader support is enabled.

Sets an accessibility option value.

Subscribe a process (by ref) to accessibility announcement events.

Unsubscribe a process (by ref) from accessibility announcement events.

Functions

announce(message, opts \\ [], user_preferences_pid_or_name)

Make an announcement for screen readers.

This function adds a message to the announcement queue that will be read by screen readers.

Parameters

  • message - The message to announce
  • opts - Options for the announcement
  • user_preferences_pid_or_name - The PID or registered name of the UserPreferences process to use (required).

Options

  • :priority - Priority level (:low, :medium, :high) (default: :medium)
  • :interrupt - Whether to interrupt current announcements (default: false)

Examples

iex> Accessibility.announce("Button clicked", [], pid)
:ok

iex> Accessibility.announce("Error occurred", [priority: :high, interrupt: true], pid)
:ok

clear_announcements()

Clear all pending announcements.

Examples

iex> Accessibility.clear_announcements()
:ok

color_scheme(opts)

Gets the current color scheme.

disable(user_preferences_pid_or_name \\ nil)

Disable accessibility features.

Examples

iex> Accessibility.disable()
:ok

enable(options \\ [], user_preferences_pid_or_name \\ nil)

Enable accessibility features with the given options.

Parameters

  • options - Options to override the default accessibility settings
  • user_preferences_pid_or_name - The PID or registered name of the UserPreferences process to use (optional).

Options

  • :high_contrast - Enable high contrast mode (default: false)
  • :reduced_motion - Enable reduced motion (default: false)
  • :large_text - Enable large text (default: false)
  • :screen_reader - Enable screen reader support (default: true)
  • :keyboard_focus - Enable keyboard focus indicators (default: true)
  • :silence_announcements - Silence screen reader announcements (default: false)

Examples

iex> Accessibility.enable(high_contrast: true)
:ok

iex> Accessibility.enable(reduced_motion: true, screen_reader: false)
:ok

font_size_multiplier(opts)

Gets the current font size multiplier.

get_color_scheme()

Get the current color scheme based on accessibility settings.

Examples

iex> Accessibility.get_color_scheme()
%{background: ...}  # Returns the current color scheme

get_component_style(component_type)

Get style settings for a component type.

Parameters

  • component_type - Atom representing the component type

Returns

  • The style map for the component type, or empty map if not found

Examples

iex> Accessibility.get_component_style(:button)
%{background: :blue}

get_element_metadata(element_id)

Get metadata for an element.

Parameters

  • element_id - Unique identifier for the element

Returns

  • The metadata map for the element, or nil if not found

Examples

iex> Accessibility.get_element_metadata("search_button")
%{label: "Search"}

get_next_announcement(user_preferences_pid_or_name)

Get the next announcement to be read by screen readers.

This function is typically called by the screen reader integration.

Examples

iex> Accessibility.get_next_announcement()
"Button clicked"

get_option(category, option, default \\ nil)

Gets an accessibility option value.

get_text_scale(user_preferences_pid_or_name \\ nil)

Get the current text scale factor based on the large text setting.

Parameters

  • user_preferences_pid_or_name - The PID or registered name of the UserPreferences process to use (optional).

Examples

iex> Accessibility.get_text_scale()
1.0 # or 1.5 if large_text is enabled

register_component_style(component_type, style)

Register style settings for a component type.

Parameters

  • component_type - Atom representing the component type
  • style - Style map to associate with the component type

Examples

iex> Accessibility.register_component_style(:button, %{background: :blue})
:ok

register_element_metadata(element_id, metadata)

Register metadata for an element to be used for accessibility features.

Parameters

  • element_id - Unique identifier for the element
  • metadata - Metadata to associate with the element

Examples

iex> Accessibility.register_element_metadata("search_button", %{label: "Search"})
:ok

screen_reader_enabled?(opts)

Checks if screen reader support is enabled.

set_high_contrast(enabled, user_preferences_pid_or_name \\ nil)

Enable or disable high contrast mode.

Parameters

  • enabled - true to enable high contrast, false to disable.
  • user_preferences_pid_or_name - The PID or registered name of the UserPreferences process to use (optional).

Examples

iex> Accessibility.set_high_contrast(true)
:ok

set_large_text(enabled, user_preferences_pid_or_name \\ nil)

Enable or disable large text mode.

Parameters

  • enabled - true to enable large text, false to disable.
  • user_preferences_pid_or_name - The PID or registered name of the UserPreferences process to use (optional).

Examples

iex> Accessibility.set_large_text(true)
:ok

set_option(category, option, value)

Sets an accessibility option value.

set_reduced_motion(enabled, user_preferences_pid_or_name \\ nil)

Enable or disable reduced motion.

Parameters

  • enabled - true to enable reduced motion, false to disable.
  • user_preferences_pid_or_name - The PID or registered name of the UserPreferences process to use (optional).

Examples

iex> Accessibility.set_reduced_motion(true)
:ok

subscribe_to_announcements(ref)

Subscribe a process (by ref) to accessibility announcement events.

unsubscribe_from_announcements(ref)

Unsubscribe a process (by ref) from accessibility announcement events.