GitHoox.Reporter (GitHoox v0.5.0)

Copy Markdown View Source

Reference :telemetry handler that prints coloured hook status to the terminal.

Sibling of GitHoox.Logger: same events, but writes plain IO lines (no log levels, no timestamps, no Logger config) so the output reads as a status report rather than a log. Attach it before running hooks:

GitHoox.Reporter.attach()

mix git_hoox.run attaches it by default; set config :git_hoox, reporter: false to opt out. Detach with GitHoox.Reporter.detach/0.

Output looks like:

 pre-commit · 3 hooks · 5 files
   Format
   Format · 38ms
   Credo
   Credo · exit 1 · 1.4s
  - Test · skipped (no matched files)
 pre-commit · 1/3 failed · 1.5s

Stages with no configured hooks print nothing (every commit fires several shims; without this they would all emit noise).

Colour

Colour is decided once at attach/0 and fixed for the handler's life. Precedence, first match wins:

  1. GIT_HOOX_COLOR=always → on, =never → off.
  2. NO_COLOR set (any value) → off.
  3. CLICOLOR_FORCE / FORCE_COLOR set and not "0" → on.
  4. IO.ANSI.enabled?/0 — true on a TTY, false through a pipe.

Pass attach(color: true) / attach(color: false) to override the detection (used by tests).

Summary

Functions

Attach the handler.

Detach the handler. Safe to call when not attached.

Functions

attach(opts \\ [])

@spec attach(keyword()) :: :ok | {:error, :already_exists}

Attach the handler.

Options:

  • :color — force colour on/off, skipping environment detection.

detach()

@spec detach() :: :ok | {:error, :not_found}

Detach the handler. Safe to call when not attached.