Ragex.CLI.Colors (Ragex v0.9.1)

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

Functions

Formats text with bold style.

Formats text with custom color and style.

Formats diff additions in green with + prefix.

Formats diff context in muted color.

Formats diff deletions in red with - prefix.

Returns true if colors are enabled.

Formats text in red for error messages.

Formats text as a section header with bold cyan.

Formats text in cyan for highlight messages.

Formats text in blue for info messages.

Formats text in dim gray for muted messages.

Formats text in green for success messages.

Formats text with underline.

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!")