在终端中内联显示 HTTPie 的图片响应,支持 iTerm2、Ghostty、kitty、WezTerm
Project description
httpie-rich-terminal
在终端中直接显示 HTTPie 的图片响应。
http https://httpbin.org/image/png
支持的终端
| 终端 | 协议 | 状态 |
|---|---|---|
| kitty | kitty graphics | 支持 |
| Ghostty | kitty graphics | 支持 |
| iTerm2 | OSC 1337 inline images | 支持 |
| WezTerm | OSC 1337 inline images | 支持 |
| tmux 内 | — | 不显示图片,打印摘要行 |
| 其他终端 | — | 不显示图片,打印摘要行 |
安装
httpie plugins install httpie-rich-terminal
若 HTTPie 是用 pip 安装的,也可以:
pip install httpie-rich-terminal
使用
装好即生效,无需额外参数:
http https://httpbin.org/image/jpeg
图片显示不出来时,插件会打印一行摘要说明原因:
[image/png 1920×1080, 245 KB — 当前终端不支持内联图片显示]
配置
全部通过环境变量控制。
| 变量 | 默认值 | 说明 |
|---|---|---|
HTTPIE_RICH_DISABLE |
0 |
设为 1 完全禁用插件,恢复 HTTPie 原生的二进制提示 |
HTTPIE_RICH_MAX_WIDTH |
终端列数 | 图片最多占用的列数 |
HTTPIE_RICH_MAX_HEIGHT |
终端行数的一半 | 图片最多占用的行数 |
HTTPIE_RICH_PROTOCOL |
auto |
强制指定协议:kitty 或 iterm2 |
HTTPIE_RICH_DEBUG |
0 |
设为 1 将检测与缩放决策打印到 stderr |
行为说明
图片不会被放大。 小于终端可用区域的图片按原始尺寸显示。
格式转换是自动的。 WebP、BMP、TIFF、AVIF 等格式会被转成 PNG 后显示。GIF 动画在 iTerm2 和 WezTerm 中可以正常播放——即使图片超出终端可用区域也会原样透传、由终端自行缩小显示,因为缩放会把动画塌缩成单帧;在 kitty 和 Ghostty 中只显示第一帧,因为 kitty 图形协议的静态传输模式不支持动画。
管道输出时插件不参与。 http ... > file.png 或 http ... | other-cmd 时 HTTPie 走原始字节流,插件不会被调用,图片数据完整无损。
已知限制
部分终端不上报像素尺寸。 插件通过 ioctl(TIOCGWINSZ) 获取终端的像素尺寸来计算缩放。少数终端会把该字段填 0,此时插件无法换算列数与像素的关系,会跳过缩放按原始尺寸输出——iTerm2 和 WezTerm 会自动把超宽图片缩放适配窗口,kitty 和 Ghostty 则会裁切超出部分。HTTPIE_RICH_MAX_WIDTH 在这种情况下同样无法生效。用 HTTPIE_RICH_DEBUG=1 可以确认是否走到了这条路径。
tmux 中不显示图片。 tmux 需要 allow-passthrough 配合各协议的特殊封装,各版本行为差异较大,当前版本选择直接跳过并打印摘要。若你已开启 allow-passthrough 并愿意自行承担风险,可以用 HTTPIE_RICH_PROTOCOL 强制指定协议绕过该检测。
只在 pretty 输出模式下生效。 这是 HTTPie 插件机制的限制:--pretty=none、--download 以及非 TTY 输出都不会走 converter 路径。
开发
uv sync
uv run pytest
uv run ruff check .
在真实终端里手动验证渲染效果:
uv run python scripts/demo.py
许可
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file httpie_rich_terminal-0.1.0.tar.gz.
File metadata
- Download URL: httpie_rich_terminal-0.1.0.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7139e67eb0d8a76d077ec982f54adc36b87cdd43d486572d5cf4dbb3ba137cf6
|
|
| MD5 |
ea1a26d63ba01d6bd256874e2805c7f8
|
|
| BLAKE2b-256 |
1daf47c782bfd9ef233a8aa2726bfa0373efeec7fae1882f841079a08a0d2ced
|
Provenance
The following attestation bundles were made for httpie_rich_terminal-0.1.0.tar.gz:
Publisher:
release.yml on moonfruit/httpie-rich-terminal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
httpie_rich_terminal-0.1.0.tar.gz -
Subject digest:
7139e67eb0d8a76d077ec982f54adc36b87cdd43d486572d5cf4dbb3ba137cf6 - Sigstore transparency entry: 2215824834
- Sigstore integration time:
-
Permalink:
moonfruit/httpie-rich-terminal@80c6fdd35978902e5190f2d9e84213ce24eaad54 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/moonfruit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@80c6fdd35978902e5190f2d9e84213ce24eaad54 -
Trigger Event:
push
-
Statement type:
File details
Details for the file httpie_rich_terminal-0.1.0-py3-none-any.whl.
File metadata
- Download URL: httpie_rich_terminal-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6f59196289740079bcea465f8cff274b3d9fa9aa42347610a1ea626a2796a6c
|
|
| MD5 |
75e0e426d6a2aba3aa9ce1482a5ce4c6
|
|
| BLAKE2b-256 |
ccb90c29fdefca7e2dbcfece41171f03a63dd4acb177ae8f0e5d55d056808652
|
Provenance
The following attestation bundles were made for httpie_rich_terminal-0.1.0-py3-none-any.whl:
Publisher:
release.yml on moonfruit/httpie-rich-terminal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
httpie_rich_terminal-0.1.0-py3-none-any.whl -
Subject digest:
e6f59196289740079bcea465f8cff274b3d9fa9aa42347610a1ea626a2796a6c - Sigstore transparency entry: 2215824847
- Sigstore integration time:
-
Permalink:
moonfruit/httpie-rich-terminal@80c6fdd35978902e5190f2d9e84213ce24eaad54 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/moonfruit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@80c6fdd35978902e5190f2d9e84213ce24eaad54 -
Trigger Event:
push
-
Statement type: