全部技能 / 基础工具与工作流 / terminal-screenshot
基础工具与工作流 · daymade/claude-code-skills

terminal-screenshot

Render a terminal CLI program's colored output to a PNG so Claude can actually SEE the real visual result — color contrast, alignment, background blocks, highlighting — instead of only reading plain text and raw ANSI escape codes. Use this whenever verifying or debugging how a CLI tool looks in the terminal: delta git diff colors, bat syntax highlighting, starship prompt, eza/ls colors, git diff, ripgrep matches, or any ANSI-colored output. ALWAYS use it right after changing any CLI color config (delta / bat / themes / lazygit pager) to visually confirm the result rather than guessing from hex values — reading a hex code is not the same as seeing the rendered contrast on the real terminal background. Trigger phrases: 看终端效果, 终端截图, 验证配色, 配色对比, 终端真实效果, terminal screenshot, render terminal output, ANSI to image, "does this color look right", "is the contrast enough", delta/bat color verification.

风险提醒:蓝色 · 知晓即可AI 侦查报告
作者 daymadeGitHub daymade/claude-code-skills ↗Stars 1385许可 MIT(仓库根 LICENSE;GitHub API spdx MIT)commit d5c4678cb5
agent 宿主通常会约束 skill 执行权限;风险提醒为 AI 侦查观点,不构成质量或安全保证。第三方 skill 仅作拆解与展示,安装使用风险自负,版权归原作者。

1实现原理 · 为什么它能做到

两步分离是核心 trick:先在被测 CLI 的真实 shell 里把全保真 ANSI 落成 .ansi 文件,再单独渲染成 PNG——绝不让渲染器替你执行命令,因为 freeze 的子 pty 会让 delta/lazygit 探测到降级环境而静默丢掉背景块/行号列/头框。

daymade-claude-code/terminal-screenshot/SKILL.md
The single most important rule: **never let the renderer run the command for you.**
注:SKILL 举反例:'`freeze --execute "git diff | delta"` looks convenient but produces a *degraded* result'。捕获侧给出每工具配方(delta/git/bat/eza/ls/rg + CLICOLOR_FORCE=1 / script -q /dev/null)。

渲染侧双层回退:render_ansi.sh 优先 freeze(charmbracelet,背景块/行号盒忠实),找不到则 python3 ansi2html.py(纯 stdlib 的 ANSI→HTML)+ 无头 Chrome 截图。

daymade-claude-code/terminal-screenshot/scripts/render_ansi.sh
# Prefers charmbracelet/freeze (faithful background blocks, line-number boxes, # window chrome). Falls back to a zero-dependency stdlib HTML renderer + # headless Chrome when freeze is not installed.
注:freeze 定位 PATH 后查 go env GOPATH/bin;Chrome 回退路径硬编码 macOS /Applications/Google Chrome.app,非 macOS 且无 freeze 时明确报错退出。

ansi2html.py 只处理真实 CLI 会发的 SGR 子集:24-bit truecolor(38;2;r;g;b/48;2;r;g;b)、256 色(38;5;n + xterm 调色板映射)、bold、reset(0/39/49);关键是把背景色块(delta 的增删底色)保真下来,文本一律 html.escape 防注入。

daymade-claude-code/terminal-screenshot/scripts/ansi2html.py
Background color blocks (48;...) are preserved faithfully — that is the whole point, since tools like delta encode add/remove as background blocks.
注:渲染循环里 `esc = H.escape(p)` 再包 span——ANSI 文本里的任何 HTML 都先被转义,产出页面无脚本注入面;xterm256 映射有独立实现(base 16 + 232 灰阶 + 6×6×6 立方)。

背景色必须匹配真实终端,否则深色主题在白底上误判对比度;SKILL 给 macOS Ghostty 取背景命令与常见默认值(#282c34/#1d1f21)。

daymade-claude-code/terminal-screenshot/SKILL.md
**Background color must match the real terminal**, or a dark theme verified on a white page looks wrong.
注:render_ansi.sh 第三参 bg_hex 默认 #282c34;'Pass it as `#282c34`.'

TUI 程序(lazygit/htop/top)被显式划出范围:它们用光标定位画全屏,不是线性 ANSI 流,无法用此法捕获;验证其颜色要拆出底层(如 lazygit 的 diff 走 delta 配置)。

daymade-claude-code/terminal-screenshot/SKILL.md
## TUI programs (lazygit, htop, top) — out of scope
注:这是能力边界声明而非缺陷:告诉 agent 什么情况该换 screencapture/computer-use 路线,防止硬套。

渲染结果由 agent 用 Read/图像工具读回做视觉判断——把『十六进制猜色』换成『看真实渲染的对比度/对齐/背景块』。

daymade-claude-code/terminal-screenshot/SKILL.md
Then read the PNG with the Read tool and judge the colors.
注:SKILL 用途定位:'ALWAYS use it right after changing any CLI color config (delta / bat / themes / lazygit pager) to visually confirm the result rather than guessing from hex values'。

2核心能力

01把任意 ANSI 着色 CLI 输出渲染成 PNG(delta/git/bat/eza/ls/rg 等),供视觉判定配色
02渲染前捕获的每工具配方表(含非 TTY 强制着色:--color=always / CLICOLOR_FORCE=1 / script -q /dev/null)
03freeze→Chrome 双层回退渲染(freeze 缺失自动降级零依赖路径)
04忠实还原背景色块/24-bit truecolor/256 色的 stdlib ANSI→HTML 转换器
05freeze 安装指引(避开同名 GUI cask:用 charmbracelet tap 或 go install + GOPROXY 镜像/GOSUMDB=off)

3外部依赖

类型依赖
clifreeze(charmbracelet/freeze,首选渲染器,可选)
cliGoogle Chrome(无头模式,回退渲染路径;路径硬编码 macOS)
clipython3(ansi2html.py 运行环境,纯 stdlib)
cligo/brew(仅安装 freeze 时的可选项)

4风险提醒 风险提醒:蓝色 · 知晓即可

风险提醒:蓝色 · 知晓即可
  • Chrome 回退路径的 --no-sandbox — 无沙箱渲染本地 HTML;内容虽已转义,若上游 .ansi 来自不可信/远程来源仍应警惕(正常用法是本地 CLI 输出)。
  • 平台局限 — Chrome 路径硬编码 macOS;Windows/Linux 无 freeze 时回退不可用(会报错退出),需改脚本或装 freeze。
  • 视觉判断仍是模型主观 — 渲染保真度依赖 freeze/Chrome 的字体与背景处理;模型对 PNG 的『对比度是否足够』判断可能有偏差,SKILL 定位为辅助证据。
风险提醒:蓝色,知晓即可。自带 stdlib/本地脚本,无网络外发、无凭证读取;渲染链为本地 freeze 或本地 Chrome 无头渲染本地文件。注意点:回退路径用 Chrome --no-sandbox(安全降级 flag,但对象是 html.escape 过的本地 HTML,无脚本注入链),Chrome 路径硬编码 macOS(非 macOS 需 freeze 否则显式报错)。

5第二遍独立确认

  • [ok] 文本是否先转义再进 HTML(防注入) — ansi2html.py 'esc = H.escape(p)' 后拼入 span/裸文本;输出文档无其他用户可控拼接。
  • [ok] Chrome --no-sandbox 与降级面 — render_ansi.sh 回退路径含 --no-sandbox;渲染对象为本地生成、已转义的 HTML;freeze 存在时该路径不触发。
  • [ok] 无网络外发/凭证读取 — 两脚本无 curl/wget/http/url/env 密钥访问;go install 仅出现在 SKILL.md 安装指引(用户主动)。
  • [ok] SKILL 声称的每工具捕获配方 — 配方表为文档层指引(agent 在 shell 执行),脚本不含这些 CLI 调用,无隐藏依赖。
  • [ok] TUI 边界声明与实现一致 — SKILL 明确 TUI 光标定位无法线性捕获;脚本只处理线性 ANSI 流输入。
  • [unlocatable] freeze/Chrome 实际渲染保真度 — 依赖外部渲染器行为(背景块/行号盒/字体度量),本环境未实装 freeze/Chrome,未做端到端截图验证。

6结论

  • 解决真实盲区:让 agent『看见』终端颜色而非读十六进制与原始转义码
  • 两步分离防降级的设计判断准确(子 pty 探测是 delta/lazygit 等真实陷阱)
  • 回退链与边界声明让它在缺 freeze/非 macOS 上仍可预期工作或明确失败
  • 注入面在实现层被处理(html.escape + 只认 m 结尾 SGR),不是靠运气
  • 适合:适合 CLI 配色/主题验证与调试工作流:delta/bat/starship/eza/ls/rg 改完颜色后立刻渲染确认;适合 agent 视觉 QA 需要『终端里人眼看到的效果』的场合;适合装得起 freeze 或 macOS+Chrome 的用户。
    不适合:不适合全屏 TUI(lazygit/htop)截图(应走真实终端截屏/computer-use);不适合无 freeze 且非 macOS 的环境(回退路径不可用);不适合需要交互式终端会话捕获而非单条输出渲染的场景。
    安装 agent 直装可复制
    ① 本站镜像 更新 2026-09-09
    方式 A · 人下载镜像包下载 terminal-screenshot.tar.gz
    sha256: f71128c440db3c5b…
    方式 B · JSON 格式安装指南,复制给 agent
    安装指南
    agent 读 JSON 指南后会自动从本站下载安装,无需更多说明。
    ② 上游 GitHub · 原始来源
    能访问 GitHub?直接去上游安装(实时版,可能已更新)GitHub 原始 ↗
    本页镜像锁定 commit d5c4678cb5;上游为实时仓库。
    来源信息 GitHub 原始
    作者 / 仓库daymade / daymade/claude-code-skills
    Stars1385
    最近推送2026-09-09
    本 skill commitd5c4678cb5
    许可MIT(仓库根 LICENSE;GitHub API spdx MIT)
    本站信息
    收录日期2026-09-06
    分类基础工具与工作流
    侦查报告2026-09-06 · 2 遍
    本站镜像与 GitHub 原始是不同来源:本站锁定 commit 快照经 /r2 分发;GitHub 为实时上游,内容可能已更新。