> [!NOTE] > 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。 > [English](./README.en.md) · [原始项目](https://github.com/charmbracelet/vhs) · [上游 README](https://github.com/charmbracelet/vhs/blob/HEAD/README.md) > 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。 # VHS


Latest Release Go Docs Build Status

以代码形式编写终端 GIF,用于集成测试和演示你的 CLI 工具。 Welcome to VHS 上面的示例由 VHS 生成([查看源码](./examples/neofetch/neofetch.tape))。 ## 教程 要开始使用,请[安装 VHS](#installation),并创建一个新的 `.tape` 文件。 ```sh vhs new demo.tape ``` 使用你喜欢的 `$EDITOR` 打开 `.tape` 文件。 ```sh vim demo.tape ``` Tape 文件由一系列[命令](#vhs-command-reference)组成。这些命令是 VHS 在其虚拟终端上执行的指令。要查看所有可用命令,请参阅[命令参考](#vhs-command-reference)。 ```elixir # Where should we write the GIF? Output demo.gif # Set up a 1200x600 terminal with 46px font. Set FontSize 46 Set Width 1200 Set Height 600 # Type a command in the terminal. Type "echo 'Welcome to VHS!'" # Pause for dramatic effect... Sleep 500ms # Run the command by pressing enter. Enter # Admire the output for a bit. Sleep 5s ``` 完成后,保存文件并将其输入 VHS。 ```sh vhs demo.tape ``` 全部完成!你应该会在目录中看到名为 `demo.gif` 的新文件(或你命名的 `Output`)。 A GIF produced by the VHS code above 更多示例请参阅 [`examples/`](https://github.com/charmbracelet/vhs/tree/main/examples) 目录。 ## 安装 > [!NOTE] > VHS 需要安装 [`ttyd`](https://github.com/tsl0922/ttyd) 和 [`ffmpeg`](https://ffmpeg.org),并确保它们在你的 `PATH` 上可用。 使用包管理器: ```sh # macOS or Linux brew install vhs # Arch Linux (btw) pacman -S vhs # Nix nix-env -iA nixpkgs.vhs # Windows using scoop scoop install vhs ``` 或者,使用 Docker 直接运行 VHS(已包含依赖): ```sh docker run --rm -v $PWD:/vhs ghcr.io/charmbracelet/vhs .tape ``` 或者,直接下载: - [Packages][releases] 提供 Debian 和 RPM 格式 - [Binaries][releases] 提供适用于 Linux、macOS 和 Windows 的版本 或者,使用 `go` 安装: ```sh go install github.com/charmbracelet/vhs@latest ```
Windows、Debian、Ubuntu、Fedora、RHEL、Void 安装说明 - Debian / Ubuntu ```sh # Debian/Ubuntu sudo mkdir -p /etc/apt/keyrings curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list # Install ttyd from https://github.com/tsl0922/ttyd/releases sudo apt update && sudo apt install vhs ffmpeg ``` - Fedora / RHEL ```sh echo '[charm] name=Charm baseurl=https://repo.charm.sh/yum/ enabled=1 gpgcheck=1 gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo # Install ttyd from https://github.com/tsl0922/ttyd/releases sudo yum install vhs ffmpeg ``` - Void ```sh sudo xbps-install vhs ``` - Windows ```sh winget install charmbracelet.vhs # or scoop scoop install vhs ```
[releases]: https://github.com/charmbracelet/vhs/releases ## 录制 Tape VHS 可以根据你的终端操作生成 tape 文件! 要录制到 tape 文件,请运行: ```bash vhs record > cassette.tape ``` 执行你想要的任何操作,然后 `exit` 终端会话以停止录制。你可能需要手动编辑生成的 `.tape` 文件,以添加设置或修改操作。然后,你可以生成 GIF: ```bash vhs cassette.tape ``` ## 发布 Tape VHS 允许你将 GIF 发布到我们的服务器,以便与朋友和同事轻松分享。指定要分享的文件,然后使用 `publish` 子命令将其托管到 `vhs.charm.sh`。输出会提供通过浏览器、HTML 和 Markdown 分享 GIF 的链接。 ```bash vhs publish demo.gif ``` ## VHS 服务器 VHS 内置了 SSH 服务器!当你自行托管 VHS 时,可以像本地安装一样访问它。VHS 将能够访问主机上的命令和应用程序,因此你无需在自己的机器上安装它们。 要启动服务器,请运行: ```sh vhs serve ```
配置选项 - `VHS_PORT`:监听的端口(`1976`) - `VHS_HOST`:监听的主机(`localhost`) - `VHS_GID`:运行服务器时使用的组 ID(当前用户的 GID) - `VHS_UID`:运行服务器时使用的用户 ID(当前用户的 UID) - `VHS_KEY_PATH`:要使用的 SSH 密钥路径(`.ssh/vhs_ed25519`) - `VHS_AUTHORIZED_KEYS_PATH`:authorized keys 文件路径(为空,可公开访问)
然后,只需通过 `ssh` 从另一台机器访问 VHS: ```sh ssh vhs.example.com < demo.tape > demo.gif ``` ## VHS 命令参考 > [!NOTE] > 你可以在命令行中使用 `vhs manual` 查看所有 VHS 文档。 VHS 命令有几种基本类型: - [`Output `](#output):指定文件输出 - [`Require `](#require):为 tape 文件指定所需程序 - [`Set Value`](#settings):设置录制参数 - [`Type ""`](#type):模拟输入 - [`Left`](#arrow-keys) [`Right`](#arrow-keys) [`Up`](#arrow-keys) [`Down`](#arrow-keys):方向键 - [`Backspace`](#backspace) [`Enter`](#enter) [`Tab`](#tab) [`Space`](#space):特殊按键 - [`ScrollUp`](#scroll-up--down) [`ScrollDown`](#scroll-up--down):滚动终端视口 - [`Ctrl[+Alt][+Shift]+`](#ctrl):按下 Control + 键和/或修饰键 - [`Sleep