生成代码和终端输出的图片。
<p align="left"> <a><img width="600" src="https://yellow-cdn.veclightyear.com/835a84d5/3f12561c-2ed1-4f19-8d3a-4900cea8fcee.gif" alt="Freeze 代码截图"></a> </p>Freeze 可以生成代码和终端输出的 PNG、SVG 和 WebP 图片。
<p align="center"> <a href="https://github.com/charmbracelet/freeze/assets/42545625/f15efdda-8e9b-4cb1-9e87-3d32b692eb7c"> <img alt="freeze 命令输出,Haskell 代码块" src="https://yellow-cdn.veclightyear.com/835a84d5/33a67ba1-14b0-4a66-9bc2-8292c5a0478b.svg" width="800" /> </a> </p>freeze artichoke.hs -o artichoke.png
你可以使用 freeze
的 --execute
标志来捕获终端命令的 ANSI 输出。
<p align="center"> <a href="https://github.com/charmbracelet/freeze/assets/42545625/aa5447ed-999a-4809-909d-67093d758f5a"> <img alt="freeze 命令输出,ANSI" src="https://yellow-cdn.veclightyear.com/835a84d5/9c8c44c4-90a9-4bdb-8f06-ed7c1a182441.svg" width="800" /> </a> </p>freeze --execute "eza -lah"
# macOS 或 Linux brew install charmbracelet/tap/freeze # Arch Linux(顺便一提) yay -S freeze # Nix nix-env -iA nixpkgs.charm-freeze
或者,下载:
或者,直接用 go
安装:
go install github.com/charmbracelet/freeze@latest
Freeze 提供完全交互式模式,方便自定义。
<img alt="freeze 交互模式" src="https://yellow-cdn.veclightyear.com/835a84d5/9eab9992-6413-47ac-b302-e8aeff80e67f.gif" width="400" />freeze --interactive
设置保存在 $XDG_CONFIG/freeze/user.json
,可以通过 freeze --config user
访问。
可以通过 --flags
或配置文件自定义截图。
[!注意] 可以通过
freeze --help
查看所有 freeze 自定义选项。
-b
,--background
:应用背景填充。-c
,--config
:基础配置文件或模板。-l
,--language
:应用于代码的语言。-m
,--margin
:为窗口添加边距。-o
,--output
:.svg、.png、.jpg 的输出位置。-p
,--padding
:为代码添加内边距。-r
,--border.radius
:窗口的角落半径。-t
,--theme
:用于语法高亮的主题。-w
,--window
:显示窗口控件。-H
,--height
:终端窗口的高度。--border.width
:边框宽度。--border.color
:边框颜色。--shadow.blur
:阴影高斯模糊。--shadow.x
:阴影 x 坐标偏移。--shadow.y
:阴影 y 坐标偏移。--font.family
:代码使用的字体系列。--font.ligatures
:在字体中使用连字。--font.size
:代码使用的字体大小。--font.file
:字体文件路 径(嵌入 SVG)。--line-height
:相对于字体大小的行高。--show-line-numbers
:显示行号。--lines
:捕获的行(开始,结束)。如果可能,freeze
会从文件名或分析文件内容自动检测语言。可以使用 --language
标志覆盖这个推断。
<br /> <a href="https://github.com/charmbracelet/freeze/assets/42545625/d746f028-3d51-4bfd-ba81-94bbc47b3587"> <img alt="freeze 命令输出,Haskell 代码块" src="https://yellow-cdn.veclightyear.com/835a84d5/ab1925ba-30c8-40af-9f5a-4277aa13de76.svg" width="600" /> </a>cat artichoke.hs | freeze --language haskell
更改颜色主题。
<br /> <a href="https://github.com/charmbracelet/freeze/assets/42545625/c693dc80-89b8-43c6-a34e-2d49a332d0c7"> <img alt="freeze 命令输出,使用 dracula 主题的 Haskell 代码块" src="https://yellow-cdn.veclightyear.com/835a84d5/17aece27-5226-48e1-b24c-33986f5e429c.svg" width="600" /> </a>freeze artichoke.hs --theme dracula
更改输出文件位置,默认为 out.svg
或管道输出时为 stdout。此值支持 .svg
、.png
、.webp
。
freeze main.go --output out.svg freeze main.go --output out.png freeze main.go --output out.webp # 或上述所有格式 freeze main.go --output out.{svg,png,webp}
指定输出图像的字体系列、字体大小和字体行高。默认为 JetBrains Mono
、14
(px)、1.2
(em)。
freeze artichoke.hs \ --font.family "SF Mono" \ --font.size 16 \ --line-height 1.4
你还可以使用 --font.file
标志嵌入字体文件(TTF、WOFF 或 WOFF2 格式)。
要在字体中使用连字,可以应用 --font.ligatures
标志。
使用 --show-line-numbers
标志在终端窗口中显示行号。
freeze artichoke.hs --show-line-numbers
要只捕获特定范围的行号,可以 使用 --lines
标志。
freeze artichoke.hs --show-line-numbers --lines 2,3
为终端添加圆角。
<br /> <a href="https://github.com/charmbracelet/freeze/assets/42545625/50932b10-56fd-4312-adbd-f64b36a15441"> <img alt="圆角为 8px 的代码截图" src="https://yellow-cdn.veclightyear.com/835a84d5/3523d76e-1742-4129-b404-1b07c9a6d341.svg" width="600" /> </a>freeze artichoke.hs --border.radius 8
为终端添加 macOS 风格的窗口控件。
<a href="https://github.com/charmbracelet/freeze/assets/42545625/ba46bc4a-fb36-4718-88d4-f63b93343615"> <img alt="freeze命令的输出,应用了窗口控件的Haskell代码块" src="https://yellow-cdn.veclightyear.com/835a84d5/954dc7fb-001f-44f9-b602-7f6d4b78384f.svg" width="600" /> </a>freeze artichoke.hs --window