Skip to content

Conversation

carli2
Copy link

@carli2 carli2 commented Sep 19, 2025

CLI passthrough (PTY), standalone snippets, and pager safeguards

Summary

  • Add command passthrough mode: run a command in a colored PTY and convert its output to HTML.
  • Introduce --standalone (-S) to emit a minimal inline HTML snippet wrapped in <code>.
  • Disable auto‑pagers in PTY by default (GIT_PAGER=cat, PAGER=cat) to prevent hangs; users can override.
  • Refresh --help, README/docs, and man page; add targeted tests.

Why

Capturing realistic colorized output from CLIs (e.g., git) usually requires a TTY. This PR makes it easy to run such commands, capture their ANSI-colored output, and convert it to HTML
reliably—without getting stuck behind pagers.

What’s Changed

  • PTY passthrough execution with argument parsing and TERM=xterm-256color.
  • --standalone (-S): like --inline but wrapped in <code style='white-space: pre;'>…</code> for convenient embedding.
  • Pager safeguards in PTY mode: set GIT_PAGER=cat and PAGER=cat by default to avoid hangs.
  • Documentation updates and new tests covering passthrough and pager behavior.

Usage

  • Run a command and convert its colored output:

    ansi2html git log -p > git-log.html
    
  • Separate ansi2html options from the child command:

    ansi2html --inline -- git log -p > inline-git-log.html

  • Produce a minimal embeddable snippet:

    echo $'\e[31mRED\e[0m' | ansi2html --standalone

    short form:

    echo $'\e[31mRED\e[0m' | ansi2html -S

Behavior Notes

  • Argument parsing:
    • After --, all args belong to the child command.
    • Without --, the first non-option token starts the child command; all following tokens belong to it.
  • PTY environment:
    • Sets TERM=xterm-256color.
    • Captures stdout and stderr together for conversion.
  • Pagers:
    • In PTY mode, sets GIT_PAGER=cat and PAGER=cat by default.
    • Override explicitly if desired, e.g. GIT_PAGER="less -R".

Docs & Tests

  • Updated: --help, README, dedicated CLI docs, and the man page.
  • Tests added/updated to cover passthrough execution and pager disabling.

Backwards Compatibility

  • Existing pipelines and options continue to work unchanged.
  • Pager behavior only changes in PTY passthrough mode and can be overridden.

Commits

  • baa58eb: cli: add --standalone (-S), disable pagers in PTY, refresh help/docs/man, add tests
  • 3d9e750: add passthrough “wrapper” mode to execute commands in a colored, non‑paged TTY

Checklist

  • PTY passthrough execution
  • --standalone (-S) snippet output
  • Pager safeguards with override
  • Docs/help/man updated
  • Tests added and passing

…e-space: pre;'> wrapper; disable pagers in PTY (GIT_PAGER/PAGER=cat); refresh --help, docs, and man page; add tests
@carli2 carli2 requested a review from ssbarnea as a code owner September 19, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant