Files
homeport--termshot/README.md
T
wehub-resource-sync 2bc2e8f779
golangci-lint / golangci-lint (push) Has been cancelled
spellcheck / spellcheck (push) Has been cancelled
Tests / Tests (push) Has been cancelled
docs: make Chinese README the default
2026-07-13 10:23:22 +00:00

147 lines
5.0 KiB
Markdown

<!-- WEHUB_ZH_README -->
> [!NOTE]
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
> [English](./README.en.md) · [原始项目](https://github.com/homeport/termshot) · [上游 README](https://github.com/homeport/termshot/blob/HEAD/README.md)
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
# termshot
[![License](https://img.shields.io/github/license/homeport/termshot.svg)](https://github.com/homeport/termshot/blob/main/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/homeport/termshot)](https://goreportcard.com/report/github.com/homeport/termshot)
[![Tests](https://github.com/homeport/termshot/workflows/Tests/badge.svg)](https://github.com/homeport/termshot/actions?query=workflow%3A%22Tests%22)
[![Codecov](https://img.shields.io/codecov/c/github/homeport/termshot/main.svg)](https://codecov.io/gh/homeport/termshot)
[![Go Reference](https://pkg.go.dev/badge/github.com/homeport/termshot.svg)](https://pkg.go.dev/github.com/homeport/termshot)
[![Release](https://img.shields.io/github/release/homeport/termshot.svg)](https://github.com/homeport/termshot/releases/latest)
在终端中生成精美的终端截图。
```sh
termshot lolcat -f <(figlet -f big termshot)
```
该命令会生成如下截图:
![示例](.doc/example-cmd-figlet.png)
## 安装
在 macOS 或 Linux 上通过 Homebrew 安装:
```sh
brew install homeport/tap/termshot
```
请参阅 [Releases](https://github.com/homeport/termshot/releases/) 获取适用于 Darwin 和 Linux 的预编译二进制文件。
## 用法
本工具读取控制台输出,并渲染成类似用户界面窗口的输出图像。其灵感来自一些基于 Web 的工具,例如 [carbon.now.sh](https://carbon.now.sh/), 和 [codekeep.io/screenshot](https://codekeep.io/screenshot).。与这些工具不同,`termshot` 不会对提供的文本盲目应用语法高亮;相反,它会读取大多数命令行工具记录的 ANSI 转义序列(「富文本」),并据此生成高保真的终端输出「截图」。
`time``watch``perf` 类似,只需在你要截图的命令前加上 `termshot` 前缀。
```sh
termshot ls -a
```
这将在当前目录生成名为 `out.png` 的图像文件。
![基础 termshot 示例](.doc/example-cmd-ls-a.png)
在某些情况下,如果目标命令包含_管道_——即使使用 `--`,仍可能存在歧义。此时请用双引号将命令包裹起来。
```sh
termshot -- "ls -1 | grep go"
```
![带管道的 termshot](.doc/example-cmd-ls-pipe-grep.png)
### 控制外观的标志
#### `--show-cmd`/`-c`
在截图中包含目标命令。
```sh
termshot --show-cmd -- "ls -a"
```
![显示命令的 termshot](.doc/example-cmd-ls-a.png)
#### `--columns`/`-C`
强制在指定列数后换行。使用此标志可确保截图不超过一定的横向长度。
#### `--no-decoration`
不绘制窗口装饰(最小化、最大化和关闭按钮)。
#### `--no-shadow`
不绘制窗口阴影。
#### `--margin`/`-m`
在窗口周围添加额外空白(外边距)。
#### `--padding`/`-p`
在窗口内的内容周围添加额外空白(内边距)。
### 与输出相关的标志
#### `--clipboard`/`-b`(仅在部分平台上可用)
不创建包含截图的输出文件,而是将截图图像保存到操作系统剪贴板。
_注意:_ 仅在部分平台上可用。运行 `termshot` help 可查看该标志是否可用。
#### `--filename`/`-f`
指定生成截图的路径。可以是绝对路径或相对路径;相对路径将相对于当前工作目录解析。默认为 `out.png`
```sh
termshot -- "ls -a" # defaults to <cwd>/out.png
termshot --filename my-image.png -- "ls -a"
termshot --filename screenshots/my-image.png -- "ls -a"
termshot --filename /Desktop/my-image.png -- "ls -a"
```
### 控制内容的标志
#### `--edit`/`-e`
在生成截图前编辑输出。这会在 `$EDITOR` 中配置的编辑器中打开富文本输出,并以 `vi` 作为后备。使用此标志可移除不需要或敏感的输出。
```sh
termshot --edit -- "ls -a"
```
### 其他标志
#### `--raw-write <file>`
将命令输出原样写入标志参数指定的文件。不会生成截图。使用 `--raw-write` 时,命令行标志 `--filename` 无效。
#### `--raw-read <file>`
从提供的文件读取输入,而不是运行命令。使用此标志时,不会创建伪终端来执行命令。使用 `--raw-read` 时,命令行标志 `--show-cmd``--edit` 无效。
#### `--version`/`-v`
打印已安装的 `termshot` 版本。
```sh
$ termshot --version
termshot version 0.2.5
```
### 多条命令
为了正常工作,`termshot` 会使用伪终端来执行命令。对于高级用法,你可以启动完全交互式的 shell,运行多条命令,并捕获全部输出。退出 shell 后将创建截图。
```sh
termshot /bin/zsh
```
> _请注意:_ 本项目仍在开发中。虽然许多 ANSI 序列可以被解析,但确实存在一些命令产生的输出尚无法被正确解析。此外,已知会重置光标位置的命令也会引发问题。