Capture a Textual terminal UI as an SVG using its headless test harness. Use when asked to make, attach, or preview a screenshot of deepagents-code/dcode or ano
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-textual-screenshot-06521b84c0e1 ,按照其中的说明把「textual-screenshot」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Render the real app with Textual's headless test harness, drive it to the requested state, and save the composed terminal as SVG. Prefer this over browser automation or OS-level screenshot tools.
App class and the shortest trusted local setup that reaches the requested UI.app.run_test(size=(columns, rows)).await pilot.pause() after startup and after every action that changes visible state. Use pilot.press(...) for a realistic interaction path when practical; direct app methods are acceptable for a focused preview.app.save_screenshot(output_path) while the desired state is visible. Use an .svg path.Minimal deepagents-code example:
import asyncio
import os
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import AsyncMock, MagicMock, patch
async def main() -> None:
output = Path("/tmp/dcode-ui.svg")
with TemporaryDirectory() as profile:
os.environ["DEEPAGENTS_HOME"] = profile
from deepagents_code.app import DeepAgentsApp
app = DeepAgentsApp(agent=MagicMock())
with patch.object(app, "_post_paint_init", new=AsyncMock()):
async with app.run_test(size=(110, 36)) as pilot:
await pilot.pause()
await app._handle_command("/model")
await pilot.pause()
app.save_screenshot(output)
print(output)
asyncio.run(main())
Run from libs/code so the project environment and editable package resolve:
uv run python /tmp/capture_dcode_ui.py
Adapt only the app constructor and action that opens the target state. For a standalone Textual app, import its App subclass and use the same run_test/save_screenshot sequence.
DeepAgentsApp, set DEEPAGENTS_HOME to a temporary directory before importing deepagents_code, and mock _post_paint_init before mounting; replacing only the agent does not isolate startup side effects.(110, 36) and adjust only when the target clips or wastes substantial space.await pilot.pause() rather than using arbitrary sleeps.