Ragex.CLI.Output (Ragex v0.14.0)

View Source

Rich output formatting utilities for tables, lists, and structured data.

Provides functions to render tabular data, lists, and other formatted output for the CLI.

Summary

Functions

Renders a formatted diff with colors.

Formats a comprehensive analysis report as text.

Renders a key-value list.

Renders a simple list with bullets.

Renders a section header with optional underline.

Renders a horizontal separator line.

Renders a progress summary with statistics.

Renders a table with headers and rows.

Types

alignment()

@type alignment() :: :left | :right | :center

table_row()

@type table_row() :: [String.t() | number()]

Functions

diff(lines)

@spec diff([{:add | :delete | :context, String.t()}]) :: :ok

Renders a formatted diff with colors.

Examples

iex> Output.diff([{:add, "new line"}, {:delete, "old line"}, {:context, "same"}])
# Renders with colors:
# + new line (green)
# - old line (red)
#   same (muted)

format_analysis_report(report)

@spec format_analysis_report(map()) :: String.t()

Formats a comprehensive analysis report as text.

Takes a report map from mix ragex.analyze and formats it for display.

Examples

text = Output.format_analysis_report(report)
IO.puts(text)

key_value(pairs, opts \\ [])

@spec key_value(
  [{String.t(), String.t()}],
  keyword()
) :: :ok

Renders a key-value list.

Options

  • :separator - Separator between key and value (default: ": ")
  • :indent - Indentation level (default: 0)
  • :key_width - Fixed width for keys (default: auto)
  • :key_color - Color for keys (default: :cyan)

Examples

iex> Output.key_value([{"Name", "Alice"}, {"Age", "30"}])
# Renders:
# Name: Alice
# Age:  30

list(items, opts \\ [])

@spec list(
  [String.t()],
  keyword()
) :: :ok

Renders a simple list with bullets.

Options

  • :bullet - Bullet character (default: "•")
  • :indent - Indentation level (default: 0)
  • :color - Color function to apply (default: nil)

Examples

iex> Output.list(["Item 1", "Item 2", "Item 3"])
# Renders:
# • Item 1
# • Item 2
# • Item 3

section(title, opts \\ [])

@spec section(
  String.t(),
  keyword()
) :: :ok

Renders a section header with optional underline.

Options

  • :underline - Character for underline (default: "=")
  • :color - Color for header (default: :cyan)

Examples

iex> Output.section("Statistics")
# Renders:
# Statistics
# ==========

separator(opts \\ [])

@spec separator(keyword()) :: :ok

Renders a horizontal separator line.

Options

  • :char - Character to use (default: "-")
  • :width - Line width (default: 80)
  • :color - Color for line (default: nil)

Examples

iex> Output.separator()
# Renders:
# --------------------------------------------------------------------------------

summary(stats)

@spec summary(map()) :: :ok

Renders a progress summary with statistics.

Examples

iex> Output.summary(%{total: 100, success: 95, errors: 5, duration: 1.5})
# Renders formatted summary with colors

table(headers, rows, opts \\ [])

@spec table([String.t()], [table_row()], keyword()) :: :ok

Renders a table with headers and rows.

Options

  • :alignments - List of alignments for each column (default: all :left)
  • :borders - Whether to draw borders (default: true)
  • :padding - Space between columns (default: 2)

Examples

iex> Output.table(["Name", "Age"], [["Alice", 30], ["Bob", 25]])
# Renders:
# Name   | Age
# -------|-----
# Alice  | 30
# Bob    | 25