Raxol.CLI.Colors (Raxol v2.6.0)

View Source

Centralized color palette for consistent CLI styling.

This module provides a unified color scheme for all terminal output, ensuring visual consistency across mix tasks, the playground, and error messages.

Design Principles

  • Semantic colors: Use purpose-based names (:success, :error) not raw colors
  • Composable: Functions return ANSI strings that can be concatenated
  • Accessible: Reasonable contrast for most terminals
  • Consistent: Same meaning everywhere in the CLI

Usage

import Raxol.CLI.Colors

# Inline styling
IO.puts(success("[OK]") <> " Task completed")
IO.puts(error("[FAIL]") <> " Something went wrong")

# With reset
IO.puts(info("Processing...") <> reset())

# Status indicators
IO.puts(status_indicator(:ok) <> " All checks passed")

# Formatted messages
IO.puts(format_success("Build complete"))
IO.puts(format_error("Compilation failed", "missing module Foo"))

Summary

Functions

Accent color (magenta) - for highlighting important items

Apply accent styling to text

Bold text

Apply bold styling to text

Box drawing characters for consistent styling

Dim/faint text

Format a divider line.

Draw a simple box around text.

Error color (red) - for failures and problems

Apply error styling to text

Format a command suggestion.

Format an error message with indicator and optional details.

Format a fix suggestion with command.

Format an info message with indicator.

Format a skip message with indicator.

Format a step in a multi-step process.

Format a success message with indicator.

Format a "Did you mean?" suggestion.

Format a timing result.

Format a warning message with indicator.

Info color (cyan) - for informational messages

Apply info styling to text

Muted color (light black/gray) - for secondary information

Apply muted styling to text

Primary color (blue) - for primary actions and headers

Apply primary styling to text

Reset all formatting

Format a section header.

Returns a formatted status indicator.

Format a subsection header.

Success color (green) - for positive outcomes

Apply success styling to text

Warning color (yellow) - for non-fatal issues

Apply warning styling to text

Functions

accent()

Accent color (magenta) - for highlighting important items

accent(text)

Apply accent styling to text

bold()

Bold text

bold(text)

Apply bold styling to text

box()

Box drawing characters for consistent styling

dim()

Dim/faint text

divider(char \\ "-", width \\ 60)

Format a divider line.

draw_box(text, opts \\ [])

Draw a simple box around text.

Examples

draw_box("Hello World", width: 20)

error()

Error color (red) - for failures and problems

error(text)

Apply error styling to text

format_command(cmd)

Format a command suggestion.

Examples

format_command("mix raxol check")
# => "mix raxol check" in cyan

format_error(message)

Format an error message with indicator and optional details.

Examples

format_error("Compilation failed")
format_error("Compilation failed", "undefined function foo/1")

format_error(message, details)

format_fix(description, command)

Format a fix suggestion with command.

Examples

format_fix("Run the formatter", "mix format")

format_info(message)

Format an info message with indicator.

format_skip(message)

Format a skip message with indicator.

format_step(current, total, description)

Format a step in a multi-step process.

Examples

format_step(1, 5, "Compiling")
# => "[1/5] Compiling"

format_success(message)

Format a success message with indicator.

Examples

format_success("Build complete")
# => "[OK] Build complete" with green indicator

format_suggestion(typo, suggestion)

Format a "Did you mean?" suggestion.

Examples

format_suggestion("chek", "check")
# => "Did you mean: check?"

format_timing(operation, milliseconds)

Format a timing result.

Examples

format_timing("Compilation", 1234)
# => "Compilation completed in 1.23s"

format_warning(message)

Format a warning message with indicator.

info()

Info color (cyan) - for informational messages

info(text)

Apply info styling to text

muted()

Muted color (light black/gray) - for secondary information

muted(text)

Apply muted styling to text

primary()

Primary color (blue) - for primary actions and headers

primary(text)

Apply primary styling to text

reset()

Reset all formatting

section_header(title)

Format a section header.

Examples

section_header("Running Tests")
# => "==> Running Tests" in cyan

status_indicator(atom)

Returns a formatted status indicator.

Examples

status_indicator(:ok)      # => "[OK]" in green
status_indicator(:error)   # => "[FAIL]" in red
status_indicator(:warning) # => "[WARN]" in yellow
status_indicator(:skip)    # => "[SKIP]" in muted
status_indicator(:info)    # => "[INFO]" in cyan

subsection_header(title)

Format a subsection header.

success()

Success color (green) - for positive outcomes

success(text)

Apply success styling to text

warning()

Warning color (yellow) - for non-fatal issues

warning(text)

Apply warning styling to text