export

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinExportFontPx    = 14
	CompactSuperSample = 2
)
View Source
const (
	ChromeMinimal     = "minimal"
	ChromeOS          = "os"
	ChromeOSWireframe = "os-wireframe" // deprecated: normalized to ChromeOS + OSStyleWireframe

	OSStyleWireframe = "wireframe"
	OSStyleMacOS     = "macos"
	OSStyleWindows   = "windows"

	BackgroundTransparent = "transparent"
	BackgroundPreset      = "preset"
	BackgroundCustom      = "custom"

	FormatPNG = "png"
	FormatSVG = "svg"

	MaxBackgroundBytes = 2 << 20 // 2 MiB
	MaxTitleLen        = 120
)

Variables

View Source
var BackgroundPresets = map[string]BackgroundSpec{
	"slate":    {Kind: "solid", Color: "#1e293b"},
	"ink":      {Kind: "solid", Color: "#0d1117"},
	"mist":     {Kind: "solid", Color: "#e2e8f0"},
	"white":    {Kind: "solid", Color: "#ffffff"},
	"sunset":   {Kind: "gradient", Start: "#f97316", End: "#7c3aed", Angle: 135},
	"ocean":    {Kind: "gradient", Start: "#0ea5e9", End: "#1e3a8a", Angle: 135},
	"forest":   {Kind: "gradient", Start: "#22c55e", End: "#14532d", Angle: 135},
	"midnight": {Kind: "gradient", Start: "#1e1b4b", End: "#0f172a", Angle: 135},
}

BackgroundPresets are named backgrounds shared by API and viewer.

View Source
var ThemeChromeAccents = map[string]ThemeChromeAccent{
	"slate": {
		Border: "#334e60", FrameBg: "#0b0c0f",
		LabelText: "#8ec8e0", LabelBg: "rgba(22, 22, 28, 0.88)", LabelBorder: "rgba(51, 78, 96, 0.55)",
	},
	"ink": {
		Border: "#3d444d", FrameBg: "#0b0c0f",
		LabelText: "#79c0ff", LabelBg: "rgba(13, 17, 23, 0.92)", LabelBorder: "rgba(88, 166, 255, 0.45)",
	},
	"mist": {
		Border: "#64748b", FrameBg: "#0b0c0f",
		LabelText: "#cbd5e1", LabelBg: "rgba(30, 41, 59, 0.88)", LabelBorder: "rgba(100, 116, 139, 0.5)",
	},
	"white": {
		Border: "#94a3b8", FrameBg: "#0b0c0f",
		LabelText: "#e2e8f0", LabelBg: "rgba(30, 41, 59, 0.9)", LabelBorder: "rgba(148, 163, 184, 0.45)",
	},
	"sunset": {
		Border: "#ea580c", FrameBg: "#0b0c0f",
		LabelText: "#fdba74", LabelBg: "rgba(28, 15, 30, 0.9)", LabelBorder: "rgba(249, 115, 22, 0.5)",
	},
	"ocean": {
		Border: "#0284c7", FrameBg: "#0b0c0f",
		LabelText: "#7dd3fc", LabelBg: "rgba(12, 20, 40, 0.9)", LabelBorder: "rgba(14, 165, 233, 0.45)",
	},
	"forest": {
		Border: "#15803d", FrameBg: "#0b0c0f",
		LabelText: "#86efac", LabelBg: "rgba(10, 28, 18, 0.9)", LabelBorder: "rgba(34, 197, 94, 0.45)",
	},
	"midnight": {
		Border: "#4f46e5", FrameBg: "#0b0c0f",
		LabelText: "#a5b4fc", LabelBg: "rgba(15, 14, 35, 0.9)", LabelBorder: "rgba(99, 102, 241, 0.45)",
	},
}

ThemeChromeAccents pairs viewer chrome accents with each export theme.

Functions

func ChromeInnerGap

func ChromeInnerGap() int

ChromeInnerGap returns space between wireframe title bar and terminal at 1x.

func ChromePadding

func ChromePadding() int

ChromePadding returns outer chrome inset at 1x for wireframe preset.

func CustomBackgroundScenePad

func CustomBackgroundScenePad() int

CustomBackgroundScenePad returns wallpaper margin around chrome at 1x export scale.

func EffectiveFontPx

func EffectiveFontPx(opts Options) int

EffectiveFontPx returns the export font size with a readability floor.

func Filename

func Filename(title, ext string) string

Filename returns a sanitized download filename from title and extension.

func GridLabelFontPx

func GridLabelFontPx() float64

GridLabelFontPx returns the grid badge font size at 1x (0.65rem @ 16px).

func InternalRenderScale

func InternalRenderScale(exportScale int) int

InternalRenderScale returns the rasterization multiplier before optional downscale.

func MacOSTerminalInset

func MacOSTerminalInset() int

MacOSTerminalInset returns text margin inside the window at 1x.

func MacOSTitleBarHeight

func MacOSTitleBarHeight() int

MacOSTitleBarHeight returns the macOS-style title bar height at 1x.

func MacOSTrafficLightGap

func MacOSTrafficLightGap() int

MacOSTrafficLightGap returns spacing between traffic lights at 1x.

func MacOSTrafficLightInset

func MacOSTrafficLightInset() int

MacOSTrafficLightInset returns traffic light offset from window edge at 1x.

func MacOSTrafficLightSize

func MacOSTrafficLightSize() int

MacOSTrafficLightSize returns traffic light diameter at 1x.

func MacOSWindowBg

func MacOSWindowBg(opts Options) color.RGBA

MacOSWindowBg returns the unified window/title bar fill for export chrome.

func MacOSWindowRadius

func MacOSWindowRadius() int

MacOSWindowRadius returns the macOS-style window corner radius at 1x.

func Render

func Render(snap term.ScreenSnapshot, opts Options, customBackground io.Reader) ([]byte, string, error)

Render produces PNG or SVG bytes for the given snapshot and options.

func RenderPNG

func RenderPNG(snap term.ScreenSnapshot, opts Options) ([]byte, error)

RenderPNG rasterizes the composed export to PNG bytes.

func RenderPNGWithBackground

func RenderPNGWithBackground(snap term.ScreenSnapshot, opts Options, custom io.Reader) ([]byte, error)

RenderPNGWithBackground rasterizes export, optionally decoding a custom backdrop.

func RenderSVG

func RenderSVG(snap term.ScreenSnapshot, opts Options) ([]byte, error)

RenderSVG returns an SVG document for the composed export.

func RenderSVGWithBackground

func RenderSVGWithBackground(snap term.ScreenSnapshot, opts Options, customBackground []byte) ([]byte, error)

RenderSVGWithBackground returns SVG, optionally embedding a custom backdrop.

func TitleBarHeight

func TitleBarHeight(chrome string, osStyle string) int

TitleBarHeight returns chrome title bar height at 1x scale.

func ViewerFramePad

func ViewerFramePad() int

ViewerFramePad returns inner padding inside the Tuile viewer frame at 1x.

func ViewerFrameRadius

func ViewerFrameRadius() int

ViewerFrameRadius returns corner radius for the viewer frame at 1x.

func WindowsAppName

func WindowsAppName() string

WindowsAppName returns the application name shown in the Windows tab.

func WindowsCaptionButtonWidth

func WindowsCaptionButtonWidth() int

WindowsCaptionButtonWidth returns caption button width at 1x. Grounded in TerminalApp/MinMaxCloseControl.xaml (Width 40).

func WindowsNewTabButtonWidth

func WindowsNewTabButtonWidth() int

WindowsNewTabButtonWidth returns the new-tab control width at 1x.

func WindowsTabActiveTopAccent

func WindowsTabActiveTopAccent(opts Options) color.RGBA

WindowsTabActiveTopAccent returns the active tab top highlight at 1x.

func WindowsTabCloseButtonWidth

func WindowsTabCloseButtonWidth() int

WindowsTabCloseButtonWidth returns the tab close control width at 1x.

func WindowsTabIconGap

func WindowsTabIconGap() int

WindowsTabIconGap returns space between tab icon and label at 1x.

func WindowsTabIconSize

func WindowsTabIconSize() int

WindowsTabIconSize returns the tab profile icon size at 1x.

func WindowsTabMenuButtonWidth

func WindowsTabMenuButtonWidth() int

WindowsTabMenuButtonWidth returns the tab menu chevron control width at 1x.

func WindowsTabPaddingX

func WindowsTabPaddingX() int

WindowsTabPaddingX returns horizontal padding inside the active tab label at 1x.

func WindowsTabRowBg

func WindowsTabRowBg(opts Options) color.RGBA

WindowsTabRowBg returns the unfocused tab row background at 1x.

func WindowsTabRowMarginTop

func WindowsTabRowMarginTop() int

WindowsTabRowMarginTop returns the tab row inset from the top window edge at 1x.

func WindowsTabRowMarginX

func WindowsTabRowMarginX() int

WindowsTabRowMarginX returns the tab row inset from the left window edge at 1x.

func WindowsTabTopRadius

func WindowsTabTopRadius() int

WindowsTabTopRadius returns the active tab top corner radius at 1x.

func WindowsTabWidth

func WindowsTabWidth() int

WindowsTabWidth returns the fixed active tab width at 1x.

func WindowsTerminalInset

func WindowsTerminalInset() int

WindowsTerminalInset returns text margin inside the window at 1x. Matches macOS: same-color band so terminal text does not hug the window edge.

func WindowsTitleBarHeight

func WindowsTitleBarHeight() int

WindowsTitleBarHeight returns the Windows Terminal tab row height at 1x. Grounded in microsoft/terminal#9093 and showTabsInTitlebar default (MS Learn).

func WindowsWindowBg

func WindowsWindowBg(opts Options) color.RGBA

WindowsWindowBg returns the unified window/title bar fill for Windows chrome.

func WindowsWindowRadius

func WindowsWindowRadius() int

WindowsWindowRadius returns the Windows-style window corner radius at 1x.

Types

type BackgroundSpec

type BackgroundSpec struct {
	Kind  string // solid | gradient
	Color string // #rrggbb for solid
	Start string // gradient start
	End   string // gradient end
	Angle int    // degrees, 135 default
}

BackgroundSpec describes a preset backdrop.

type Layout

type Layout struct {
	ExportScale   int
	RenderScale   int
	Downscale     int
	CellW         int
	CellH         int
	TermW         int
	TermH         int
	ChromePad     int
	TitleBar      int
	InnerGap      int
	FramePad      int
	FrameRadius   int
	FrameW        int
	FrameH        int
	RenderOuterW  int
	RenderOuterH  int
	OuterW        int
	OuterH        int
	TermOffsetX   int
	TermOffsetY   int
	Cols          int
	Rows          int
	Wireframe     bool
	OSStyle       string
	WindowRadius  int
	Border        int
	ScenePad      int
	ChromeW       int
	ChromeH       int
	ChromeOffsetX int
	ChromeOffsetY int
}

Layout describes export canvas dimensions in pixels.

func ComputeLayout

func ComputeLayout(snap term.ScreenSnapshot, opts Options) Layout

ComputeLayout derives pixel dimensions from screen and options.

func ScaleLayoutToOuter

func ScaleLayoutToOuter(layout Layout) Layout

ScaleLayoutToOuter converts render-space layout into final SVG/output pixels. Gwenview and other Qt SVG renderers mishandle nested transform scale groups.

type Options

type Options struct {
	ChromePreset     string `json:"chrome_preset"`
	ChromeOSStyle    string `json:"chrome_os_style,omitempty"`
	BackgroundMode   string `json:"background_mode"`
	BackgroundPreset string `json:"background_preset,omitempty"`
	Scale            int    `json:"scale"`
	Format           string `json:"format"`
	FontFamily       string `json:"font_family,omitempty"`
	FontSizePx       int    `json:"font_size_px,omitempty"`
	TermWPx          int    `json:"term_w_px,omitempty"`
	TermHPx          int    `json:"term_h_px,omitempty"`
	Theme            string `json:"theme,omitempty"`
	Title            string `json:"title,omitempty"`
	ShowGridSize     bool   `json:"show_grid_size"`
}

Options configures a terminal screenshot export.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns export defaults aligned with the browser viewer.

func (Options) IsOSChrome

func (o Options) IsOSChrome() bool

IsOSChrome reports whether export uses an OS window frame.

func (Options) LayoutScale

func (o Options) LayoutScale() int

LayoutScale returns the pixel multiplier for output dimensions.

func (*Options) NormalizeChrome

func (o *Options) NormalizeChrome()

NormalizeChrome maps legacy presets and fills OS style defaults.

func (Options) ResolvedOSStyle

func (o Options) ResolvedOSStyle() string

ResolvedOSStyle returns the active OS chrome style after normalization.

func (*Options) Validate

func (o *Options) Validate() error

Validate normalizes and checks export options.

type ThemeChromeAccent

type ThemeChromeAccent struct {
	Border      string
	FrameBg     string
	LabelText   string
	LabelBg     string
	LabelBorder string
}

ThemeChromeAccent holds viewer frame border and grid badge colors for a theme.

func ThemeChromeAccentFor

func ThemeChromeAccentFor(opts Options) ThemeChromeAccent

ThemeChromeAccentFor returns viewer chrome accents for the active export theme.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL