Search documentation of Ragex

# Ragex.CLI.Colors (Ragex v0.4.0)

View Source

ANSI color helpers for CLI output.

Provides convenience functions for colored terminal output with support for NO_COLOR environment variable.

## Examples

    iex> Colors.success("Operation successful!")
    "\e[32mOperation successful!\e[0m"

    iex> Colors.error("Something went wrong")
    "\e[31mSomething went wrong\e[0m"

## Summary

### Types

color()
style()

### Functions

bold(text)

Formats text with bold style.

colorize(text, color, style \\ :normal)

Formats text with custom color and style.

diff_add(text)

Formats diff additions in green with + prefix.

diff_context(text)

Formats diff context in muted color.

diff_delete(text)

Formats diff deletions in red with - prefix.

enabled?()

Returns true if colors are enabled.

error(text)

Formats text in red for error messages.

header(text)

Formats text as a section header with bold cyan.

highlight(text)

Formats text in cyan for highlight messages.

info(text)

Formats text in blue for info messages.

muted(text)

Formats text in dim gray for muted messages.

success(text)

Formats text in green for success messages.

underline(text)

Formats text with underline.

warning(text)

Formats text in yellow for warning messages.

## Types

# color()

    @type color() :: :black | :red | :green | :yellow | :blue | :magenta | :cyan | :white

# style()

    @type style() :: :normal | :bright | :faint | :italic | :underline

## Functions

# bold(text)

    @spec bold(String.t()) :: String.t()

Formats text with bold style.

## Examples

    IO.puts Colors.bold("Important")

# colorize(text, color, style \\ :normal)

    @spec colorize(String.t(), color(), style()) :: String.t()

Formats text with custom color and style.

## Examples

    IO.puts Colors.colorize("Custom", :magenta, :italic)

# diff_add(text)

    @spec diff_add(String.t()) :: String.t()

Formats diff additions in green with + prefix.

## Examples

    IO.puts Colors.diff_add("+ new line")

# diff_context(text)

    @spec diff_context(String.t()) :: String.t()

Formats diff context in muted color.

## Examples

    IO.puts Colors.diff_context("  context line")

# diff_delete(text)

    @spec diff_delete(String.t()) :: String.t()

Formats diff deletions in red with - prefix.

## Examples

    IO.puts Colors.diff_delete("- old line")

# enabled?()

    @spec enabled?() :: boolean()

Returns true if colors are enabled.

Colors are disabled when:

- NO_COLOR environment variable is set
- TERM environment variable is "dumb"
- Output is not a TTY

# error(text)

    @spec error(String.t()) :: String.t()

Formats text in red for error messages.

## Examples

    IO.puts Colors.error("Failed!")

# header(text)

    @spec header(String.t()) :: String.t()

Formats text as a section header with bold cyan.

## Examples

    IO.puts Colors.header("Step 1: Analysis")

# highlight(text)

    @spec highlight(String.t()) :: String.t()

Formats text in cyan for highlight messages.

## Examples

    IO.puts Colors.highlight("Important!")

# info(text)

    @spec info(String.t()) :: String.t()

Formats text in blue for info messages.

## Examples

    IO.puts Colors.info("Processing...")

# muted(text)

    @spec muted(String.t()) :: String.t()

Formats text in dim gray for muted messages.

## Examples

    IO.puts Colors.muted("(optional)")

# success(text)

    @spec success(String.t()) :: String.t()

Formats text in green for success messages.

## Examples

    IO.puts Colors.success("Done!")

# underline(text)

    @spec underline(String.t()) :: String.t()

Formats text with underline.

## Examples

    IO.puts Colors.underline("Link")

# warning(text)

    @spec warning(String.t()) :: String.t()

Formats text in yellow for warning messages.

## Examples

    IO.puts Colors.warning("Be careful!")