Raxol.UI.Accessibility.HighContrast (Raxol v2.0.1)

View Source

High contrast mode system for improved visual accessibility in Raxol terminals.

This module provides comprehensive high contrast support including:

  • Multiple high contrast themes (black/white, white/black, custom)
  • WCAG 2.1 AA and AAA contrast ratio compliance
  • Automatic contrast adjustment for different lighting conditions
  • Color blindness accommodation (Deuteranopia, Protanopia, Tritanopia)
  • Large text mode with scalable fonts
  • Custom user-defined contrast schemes
  • System integration with OS accessibility settings
  • Dynamic contrast adjustment based on ambient light
  • Color palette optimization for terminal interfaces

Features

Contrast Modes

  • High Contrast Black (white text on black background)
  • High Contrast White (black text on white background)
  • High Contrast Custom (user-defined color schemes)
  • Inverted Colors mode
  • Grayscale mode with enhanced contrast
  • Adaptive contrast based on content type

Accessibility Compliance

  • WCAG 2.1 Level AA (4.5:1 contrast ratio)
  • WCAG 2.1 Level AAA (7:1 contrast ratio)
  • Color blindness simulation and correction
  • Focus indicator enhancement
  • Text shadow and outline options for improved readability

Usage

# Initialize high contrast system
{:ok, hc} = HighContrast.start_link(
  default_theme: :high_contrast_black,
  compliance_level: :wcag_aa,
  auto_detect_system: true,
  color_blind_support: true
)

# Apply high contrast theme
HighContrast.apply_theme(hc, :high_contrast_white)

# Create custom theme with WCAG compliance
custom_theme = %{
  name: "custom_blue",
  background: {0, 0, 51},      # Dark blue
  foreground: {255, 255, 204}, # Light yellow
  accent: {255, 102, 0},       # Orange
  compliance_level: :wcag_aaa
}
HighContrast.register_theme(hc, custom_theme)

# Enable color blindness accommodation
HighContrast.configure_color_blindness(hc, :deuteranopia, %{
  strength: 0.8,
  enable_patterns: true,
  alternative_indicators: [:shapes, :textures]
})

Summary

Functions

Applies a high contrast theme.

Returns a specification to start this module under a supervisor.

Configures color blindness accommodation.

Creates a custom theme builder with WCAG validation.

Gets accessibility information for the current theme.

Gets the current active theme.

Lists all available themes.

Registers a custom high contrast theme.

Enables or disables large text mode.

Suggests improved colors for better contrast.

Toggles color inversion.

Validates contrast ratio compliance for a color pair.

Types

color_blindness_type()

@type color_blindness_type() ::
  :deuteranopia | :protanopia | :tritanopia | :achromatopsia

compliance_level()

@type compliance_level() :: :wcag_a | :wcag_aa | :wcag_aaa

config()

@type config() :: %{
  default_theme: theme_name(),
  compliance_level: compliance_level(),
  auto_detect_system: boolean(),
  color_blind_support: boolean(),
  large_text_mode: boolean(),
  adaptive_contrast: boolean(),
  ambient_light_adjustment: boolean(),
  focus_enhancement: boolean(),
  text_shadow: boolean(),
  invert_colors: boolean()
}

contrast_ratio()

@type contrast_ratio() :: float()

rgb_color()

@type rgb_color() :: {0..255, 0..255, 0..255}

theme()

@type theme() :: %{
  name: theme_name(),
  background: rgb_color(),
  foreground: rgb_color(),
  accent: rgb_color(),
  secondary: rgb_color(),
  success: rgb_color(),
  warning: rgb_color(),
  error: rgb_color(),
  info: rgb_color(),
  border: rgb_color(),
  shadow: rgb_color(),
  compliance_level: compliance_level(),
  large_text_optimized: boolean()
}

theme_name()

@type theme_name() :: atom()

Functions

apply_theme(hc \\ __MODULE__, theme_name)

Applies a high contrast theme.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

configure_color_blindness(hc \\ __MODULE__, type, options \\ %{})

Configures color blindness accommodation.

create_theme_builder(base_colors, target_compliance \\ :wcag_aa)

Creates a custom theme builder with WCAG validation.

get_accessibility_info(hc \\ __MODULE__)

Gets accessibility information for the current theme.

get_current_theme(hc \\ __MODULE__)

Gets the current active theme.

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

handle_manager_info(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.

list_themes(hc \\ __MODULE__)

Lists all available themes.

register_theme(hc \\ __MODULE__, theme)

Registers a custom high contrast theme.

set_large_text_mode(hc \\ __MODULE__, enabled)

Enables or disables large text mode.

start_link(init_opts \\ [])

suggest_contrast_improvement(hc \\ __MODULE__, foreground, background)

Suggests improved colors for better contrast.

toggle_invert_colors(hc \\ __MODULE__)

Toggles color inversion.

validate_contrast(hc \\ __MODULE__, foreground, background, options \\ %{})

Validates contrast ratio compliance for a color pair.