终端截图
- 作者仓库星标 0
- 作者更新于 2026年8月24日 07:33
- 作者仓库 claude-code-skills
- 领域
- 通用
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @daymade · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- macOS
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 命令执行
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# after editing [delta] colors in gitconfig, in any repo with a diff:
git --no-pager diff | delta --dark --line-numbers --width=110 > /tmp/diff.ansi
scripts/render_ansi.sh /tmp/diff.ansi /tmp/diff.png "#282c34"
# then: Read /tmp/diff.png and judge whether add/remove contrast is clear
第 1 步 — 将全保真 ANSI 捕获到文件中
大多数 CLI 在检测到它们没有写入真实终端(管道或子进程)时会删除或降级颜色。强制全着色并保存到`.ansi`文件。确切的标志取决于工具 - 下面的食谱。最重要的一条规则:永远不要让渲染器为您运行命令。 `freeze --execute "git diff | delta"` 看起来很方便,但会产生*降级*
步骤 2 — 将 ANSI 文件渲染为 PNG,然后读取它
使用捆绑的包装器,它更喜欢 `freeze` 并回退到 stdlib 渲染器 + 无头 Chrome:然后使用读取工具读取 PNG 并判断颜色。背景颜色必须与真实终端匹配,否则在白页上验证的深色主题看起来是错误的。在装有 Ghostty 的 macOS 上:
# Terminal Screenshot
Render the colored output of a terminal command into a PNG image, then read that
image to judge the result visually.
## Why this exists
When a command's output arrives as a tool result, Claude sees plain text plus raw
escape codes like `\x1b[48;2;92;30;34m` — not the rendered colors. That makes it
impossible to honestly answer "is the diff's add/remove contrast strong enough?"
or "did this theme come out too dark?". Reading hex values is guessing. This skill
turns the output into an image so the judgement is based on what a human would
actually see on screen.
## The method: capture, then render
Two separate steps. Keep them separate — that separation is the whole trick.
### Step 1 — Capture full-fidelity ANSI to a file
Most CLIs **drop or downgrade colors when they detect they're not writing to a
real terminal** (a pipe or a child process). Force full coloring and save to a
`.ansi` file. The exact flag depends on the tool — recipes below.
The single most important rule: **never let the renderer run the command for you.**
`freeze --execute "git diff | delta"` looks convenient but produces a *degraded*
result — delta (and lazygit, and anything that probes terminal capabilities) runs
inside freeze's child pty, detects a reduced environment, and silently drops its
background blocks, line-number column, and header box. Capture in a normal shell
first, render second.
### Step 2 — Render the ANSI file to PNG, then read it
Use the bundled wrapper, which prefers `freeze` and falls back to a stdlib
renderer + headless Chrome:
```bash
scripts/render_ansi.sh <input.ansi> <output.png> [background_hex]
```
Then read the PNG with the Read tool and judge the colors.
**Background color must match the real terminal**, or a dark theme verified on a
white page looks wrong. On macOS with Ghostty:
```bash
ghostty +show-config --default | grep '^background' # e.g. 282c34 (the default)
```
Pass it as `#282c34`. If unknown, a dark terminal is usually near `#1d1f21`–`#282c34`.
## Capture recipes per tool
Pick a `--width` close to the real terminal (≈100–120) so wrapping matches.
| Tool | Capture command (writes full-color ANSI) |
|------|------------------------------------------|
| **delta** (git diff) | `git --no-pager diff \| delta --dark --line-numbers --width=110 > /tmp/x.ansi` |
| **git diff** (native) | `git -c color.ui=always --no-pager diff > /tmp/x.ansi` |
| **bat** | `bat --color=always --style=numbers <file> > /tmp/x.ansi` |
| **eza** | `eza -la --color=always --icons > /tmp/x.ansi` |
| **ls** (GNU) | `ls -la --color=always > /tmp/x.ansi` |
| **ls** (macOS/BSD) | `CLICOLOR_FORCE=1 ls -laG > /tmp/x.ansi` |
| **ripgrep** | `rg --color=always 'pattern' <path> > /tmp/x.ansi` |
| **anything else** | `CLICOLOR_FORCE=1 <cmd> > /tmp/x.ansi` or `<cmd> --color=always`, or wrap in a real pty: `script -q /dev/null <cmd>` |
Note `delta` always emits its configured colors even to a file, so the only trap
for delta is Step 1's rule (don't render it via `freeze --execute`).
### Full example: verify a delta color change
```bash
# after editing [delta] colors in gitconfig, in any repo with a diff:
git --no-pager diff | delta --dark --line-numbers --width=110 > /tmp/diff.ansi
scripts/render_ansi.sh /tmp/diff.ansi /tmp/diff.png "#282c34"
# then: Read /tmp/diff.png and judge whether add/remove contrast is clear
```
## TUI programs (lazygit, htop, top) — out of scope
Full-screen TUIs paint with cursor positioning, not a linear ANSI stream, so they
can't be captured this way. To check a TUI's *colors*, verify the underlying piece
in isolation — e.g. for lazygit's diff, render `git diff | delta` as above (lazygit
calls the same delta config). For a true TUI screenshot, run it in a real terminal
and capture the screen (a screencapture/computer-use task), not this skill.
## Installing freeze (the preferred renderer)
`freeze` is [charmbracelet/freeze](https://github.com/charmbracelet/freeze) — it
renders ANSI to PNG/SVG/WebP with faithful background blocks and nice chrome.
**Do not run `brew install freeze`** — that installs an unrelated GUI app of the
same name (a cask). The CLI lives in charmbracelet's tap or via `go install`:
```bash
# Option A — Homebrew tap (needs GitHub reachable)
brew install charmbracelet/tap/freeze
# Option B — go install (works behind a firewall via a Go module mirror)
GOPROXY=https://goproxy.cn,direct GOSUMDB=off \
go install github.com/charmbracelet/freeze@latest
# binary lands in "$(go env GOPATH)/bin/freeze"
```
`GOSUMDB=off` is needed when the checksum database (`sum.golang.org`) is
unreachable and `go install` hangs on "verifying module ... 504".
If freeze can't be installed, the wrapper automatically falls back to the bundled
`scripts/ansi2html.py` (stdlib only) + headless Chrome — no extra dependency
beyond a Chrome install. The fallback uses a fixed window size; widen
`--window-size` in `render_ansi.sh` if output is clipped.
## Bundled scripts
- `scripts/render_ansi.sh` — render a captured `.ansi` file to PNG (freeze, else
Chrome fallback). This is the entry point; call it after Step 1.
- `scripts/ansi2html.py` — stdlib ANSI→HTML converter used by the fallback path.
Handles 24-bit truecolor, 256-color, bold, and resets, preserving background
color blocks (the part naive renderers drop).
## Common pitfalls
- **Letting the renderer run the command** (`freeze --execute "delta …"`) →
degraded output. Capture in a normal shell first, render the file second.
- **Non-TTY strips color** → force it (`--color=always` / `CLICOLOR_FORCE=1` /
`script -q /dev/null`).
- **Wrong background color** → a dark CLI theme rendered on a white page misjudges
contrast. Use the real terminal background.
- **Light/dark mismatch** → if the terminal is dark, the CLI's colors must be its
dark variant. Verifying a `light=true` config against a dark terminal shows
inverted, hard-to-read colors (and is itself the bug, not the renderer's fault).
- **`brew install freeze`** installs the wrong (GUI cask) tool — use the tap or
`go install`.
章节与文件索引
按说明文件中的顺序排列。
为什么存在这个
方法:捕获,然后渲染
第 1 步 — 将全保真 ANSI 捕获到文件中
步骤 2 — 将 ANSI 文件渲染为 PNG,然后读取它
捕获每个工具的食谱
文件/命令 -> \x1b[48;2;92;30;34m · .ansi · freeze --execute "git diff | delta" · freeze · #282c34 · #1d1f21 · --width · git --no-pager diff \| delta --dark --line-numbers --width=110 > /tmp/x.ansi
内容校验值 -> c5a233c95015
当前原文的自动摘译,尚未人工审校。
为什么存在这个
当命令的输出作为工具结果到达时,Claude 会看到纯文本加上原始转义码(如
\x1b[48;2;92;30;34m),而不是渲染的颜色。这使得不可能诚实地回答“差异的添加/删除对比度是否足够强?”或者“这个主题是否太暗了?”。读取十六进制值是猜测。这项技能将输出转化为图像,因此判断是基于人类的判断方法:捕获,然后渲染
两个单独的步骤。让它们分开——分开就是整个技巧。
捕获每个工具的食谱
选择一个接近真实终端的
--width(约100-120),以便包装匹配。工具 · 捕获命令(写入全彩 ANSI) delta (git diff) ·git --no-pager diff \ · delta --dark --line-numbers --width=110 > /tmp/x.ansigit diff (本机) ·git -c color.ui=always --no-pager diff > /tmp/x.ansibat ·bat --color=always --style=numbers <file> > /tmp/x.ansi