Skip to content

Investigate inline snapshot rendering in capable terminals #125

@obj-p

Description

@obj-p

Motivation

preview snapshot currently writes a PNG to disk and prints the path. For users on terminals that support inline images, we could render the snapshot directly in the terminal after (or instead of) writing the file — a much tighter feedback loop for iterating on UI.

Candidate protocols

  • iTerm2 inline images — base64-encoded OSC 1337 escape (ESC ] 1337 ; File=...). Widely supported by iTerm2, WezTerm.
  • Kitty graphics protocol — chunked OSC escape with broader capabilities; supported by Kitty, WezTerm, Ghostty.
  • Sixel — older standard; supported by mlterm, foot, some xterm builds.

Open questions

  • How do we detect terminal capability? ($TERM_PROGRAM, $TERM, $KITTY_WINDOW_ID, terminfo queries via XTGETTCAP?)
  • Opt-in flag, opt-out flag, or auto-detect with override?
  • Behavior when piping stdout (e.g. preview snapshot | jq) — should suppress images.
  • Behavior in --json mode — keep path-only, or embed base64?
  • Downscale large snapshots before emitting so we don't blow up the scrollback? What's the right max width?
  • Does this fit in PreviewsCLI directly, or warrant a small helper module?

Acceptance criteria (tentative)

  • Capability detection for at least iTerm2 + Kitty
  • Graceful fallback to path-only output on unsupported terminals or non-TTY stdout
  • Does not interfere with --json / scripting workflows
  • Covered by tests (capability detection at minimum; rendering likely needs a manual checklist)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions