click_extra.capture.presets module¶
The bundled catalog of terminal presets a capture can be drawn as.
A capture is a picture of a terminal, and terminals do not look alike. A preset carries the five things that make one recognizable, so a reader placing the image knows which desktop it came from:
the window decorations, three round buttons on the left for macOS, three glyphs on the right for Windows, a single one for GNOME;
the palette its colors resolve against, which is what turns a bright blue into Campbell’s
#3B78FFor Tango’s#729FCF;the font the terminal ships with;
the prompt its shell draws,
$againstPS C:\>;the cursor it draws, a block everywhere but Windows Terminal, which opens on a bar.
None of it is applied unless asked for: a capture with no preset keeps the
renderer’s own neutral window. That window is described here too:
DEFAULT_PRESET is the terminal it resolves its colors against,
TerminalBackground names the dark or light chrome a
capture is drawn on, and resolve_palette() answers the palette any preset
shows on either.
Chrome draws the rest of the window: its frame, shadow, margins and
credit line.
Caution
A palette here is a published default, transcribed from the scheme each terminal ships (Campbell and One Half Light for Windows Terminal, Basic and Pro for Apple’s Terminal, Tango for GNOME), and cross-checked against iTerm2-Color-Schemes. It is what the terminal looks like out of the box, not what any given reader has configured theirs to.
- class click_extra.capture.presets.TerminalPalette(background, foreground, ansi, titlebar)[source]¶
Bases:
NamedTupleThe colors a terminal resolves a capture’s ANSI codes against.
The 16
ansientries are the standard palette in the canonical order: black, red, green, yellow, blue, magenta, cyan, white, then the same eight in their bright variants.Create new instance of TerminalPalette(background, foreground, ansi, titlebar)
- class click_extra.capture.presets.WindowButtons(circles=(), glyphs='')[source]¶
Bases:
NamedTupleThe decorations a terminal draws in its title bar.
Two shapes cover the desktops: macOS draws filled circles on the left, Windows and GNOME draw glyphs on the right. An empty field leaves that half undrawn, which is what a bare window asks for.
Create new instance of WindowButtons(circles, glyphs)
- click_extra.capture.presets.MACOS_BUTTONS: Final = (('#ff5f57', '#febc2e', '#28c840'), '')¶
Close, minimize and zoom, the three round buttons of an Aqua title bar.
- click_extra.capture.presets.WINDOWS_BUTTONS: Final = ((), '-□✕')¶
Minimize, maximize and close, the three glyphs of a Windows title bar.
- click_extra.capture.presets.GNOME_BUTTONS: Final = ((), '✕')¶
The single close button a GNOME window carries by default.
- class click_extra.capture.presets.CursorShape(*values)[source]¶
Bases:
EnumThe shape a terminal draws its cursor as.
The three every terminal offers, under the names they are configured by. Which one a terminal picks out of the box is part of what makes it recognizable, so a preset states it alongside the buttons and the font.
- BLOCK = 'block'¶
A filled cell, the shape a terminal draws unless told otherwise.
- BAR = 'bar'¶
A thin upright line on the cell’s leading edge.
- UNDERLINE = 'underline'¶
A thin line along the cell’s bottom edge.
- class click_extra.capture.presets.Cursor(shape=None, blink=1.0, color=None)[source]¶
Bases:
NamedTupleThe cursor a capture draws, and how it behaves.
Passed to
render_svg()to draw one at all: a capture shows no cursor unless asked.Note
Where the cursor is is never stated here. A frame’s text already says so, see
cursor_cell(), so a caller states what the cursor looks like and the picture answers for the rest.Create new instance of Cursor(shape, blink, color)
- shape: CursorShape | None¶
How it is drawn.
Nonetakes the shape the terminal preset names.
- blink: float¶
Seconds one blink takes, half of it lit. Zero draws a steady cursor.
A second is what the desktops settle around, and it is deliberately no factor of any frame interval: the two clocks drift against each other across a loop, which is what a terminal showing a cursor over a running command looks like.
Caution
Blinking is motion, and a reader may have asked their system for less of it. The rule sits behind
REDUCED_MOTION_QUERYlike every other animation this package emits, which leaves the cursor lit and still. That guard is also what answers WCAG 2.2.2, which asks that anything blinking past five seconds can be stopped.
- click_extra.capture.presets.APPLE_ANSI: Final = ('#000000', '#c23621', '#25bc24', '#adad27', '#492ee1', '#d338d3', '#33bbc8', '#cbcccd', '#818383', '#fc391f', '#31e722', '#eaec23', '#5833ff', '#f935f8', '#14f0f0', '#e9ebeb')¶
Palette shared by Apple Terminal’s
BasicandProschemes.
- click_extra.capture.presets.CAMPBELL_ANSI: Final = ('#0c0c0c', '#c50f1f', '#13a10e', '#c19c00', '#0037da', '#881798', '#3a96dd', '#cccccc', '#767676', '#e74856', '#16c60c', '#f9f1a5', '#3b78ff', '#b4009e', '#61d6d6', '#f2f2f2')¶
Palette of
Campbell, the scheme Windows Terminal opens with.
- click_extra.capture.presets.ONE_HALF_LIGHT_ANSI: Final = ('#383a42', '#e45649', '#50a14f', '#c18301', '#0184bc', '#a626a4', '#0997b3', '#fafafa', '#4f525d', '#df6c75', '#98c379', '#e4c07a', '#61afef', '#c577dd', '#56b5c1', '#ffffff')¶
Palette of
One Half Light, the light scheme Windows Terminal ships.
- click_extra.capture.presets.TANGO_ANSI: Final = ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec')¶
Palette of Tango, which GNOME Terminal ships in a dark and a light dress.
- class click_extra.capture.presets.TerminalPreset(label, buttons, radius, prompt, cursor, font_stack, dark, light)[source]¶
Bases:
NamedTupleA terminal a capture can be drawn as.
Pass one to
click-extra screenshot --preset, or to aclick:runblock as:screenshot-preset:. Anything stated alongside it wins: a preset picks the defaults, it does not lock them.Create new instance of TerminalPreset(label, buttons, radius, prompt, cursor, font_stack, dark, light)
- buttons: WindowButtons¶
Decorations drawn in the title bar, see
WindowButtons.
- cursor: CursorShape¶
Shape it draws its cursor as, see
CursorShape.Only consulted by a capture that asked for a cursor: a preset picks the shape, it never turns one on.
- font_stack: str¶
Fonts the capture asks for, the terminal’s own first.
Nothing is embedded, so a reader without the family falls back down the list. Which is why each ends with the same generic
monospacea browser always resolves.
- dark: TerminalPalette¶
Colors the terminal shows on its dark scheme.
- light: TerminalPalette¶
Colors it shows on its light one.
- click_extra.capture.presets.PRESETS: Final[dict[str, TerminalPreset]] = {'linux': ('GNOME Terminal', ((), '✕'), 6, '$', CursorShape.BLOCK, "'Ubuntu Mono', 'DejaVu Sans Mono', monospace", ('#2e3436', '#d3d7cf', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#303030'), ('#ffffff', '#2e3436', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#ebebeb')), 'macos': ('Apple Terminal', (('#ff5f57', '#febc2e', '#28c840'), ''), 10, '$', CursorShape.BLOCK, "'SF Mono', Menlo, Monaco, monospace", ('#000000', '#f2f2f2', ('#000000', '#c23621', '#25bc24', '#adad27', '#492ee1', '#d338d3', '#33bbc8', '#cbcccd', '#818383', '#fc391f', '#31e722', '#eaec23', '#5833ff', '#f935f8', '#14f0f0', '#e9ebeb'), '#3a3a3a'), ('#ffffff', '#000000', ('#000000', '#c23621', '#25bc24', '#adad27', '#492ee1', '#d338d3', '#33bbc8', '#cbcccd', '#818383', '#fc391f', '#31e722', '#eaec23', '#5833ff', '#f935f8', '#14f0f0', '#e9ebeb'), '#e9e9e9')), 'plain': ('No terminal at all', ((), ''), 0, '$', CursorShape.BLOCK, "'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace", ('#292929', '#c5c8c6', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#292929'), ('#ffffff', '#000000', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#ffffff')), 'windows': ('Windows Terminal', ((), '-□✕'), 0, 'PS C:\\>', CursorShape.BAR, "'Cascadia Code', 'Cascadia Mono', Consolas, monospace", ('#0c0c0c', '#cccccc', ('#0c0c0c', '#c50f1f', '#13a10e', '#c19c00', '#0037da', '#881798', '#3a96dd', '#cccccc', '#767676', '#e74856', '#16c60c', '#f9f1a5', '#3b78ff', '#b4009e', '#61d6d6', '#f2f2f2'), '#202020'), ('#fafafa', '#383a42', ('#383a42', '#e45649', '#50a14f', '#c18301', '#0184bc', '#a626a4', '#0997b3', '#fafafa', '#4f525d', '#df6c75', '#98c379', '#e4c07a', '#61afef', '#c577dd', '#56b5c1', '#ffffff'), '#f3f3f3'))}¶
Every terminal a capture can be drawn as, alphabetically.
plainis the odd one out: it mimics no desktop, dropping the buttons and the rounded corners for a capture that has to read as a block of output rather than as a window, on a slide or in a paper.
- click_extra.capture.presets.DEFAULT_PRESET: Final = ('No terminal at all', ((), ''), 0, '$', CursorShape.BLOCK, "'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace", ('#292929', '#c5c8c6', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#292929'), ('#ffffff', '#000000', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#ffffff'))¶
Terminal a capture with no
--presetis drawn as.plainmimics no desktop, which is what a capture wearing no decoration should resolve its colors against. Naming it here is what keeps the two formats looking like the same terminal, and keeps one catalog answering for every palette a capture can use: without it the default colors would be a second set of literals free to drift from the one the presets publish.
- click_extra.capture.presets.CAPTURE_FONT_STACK: Final = "'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace"¶
Monospaced fonts a capture asks for, best first.
Nothing is embedded and nothing is fetched, so both formats set the text in the first family the reader already has, and a capture renders the same offline, on a page forbidding third-party requests, and in a viewer that speaks no CSS
@font-face.Family names are single-quoted on purpose: this lands in a double-quoted
styleattribute, which a double quote here would terminate early.Note
Not embedding is a decision, not an omission: a subsetted font would ship inside this package, and redistribute someone else’s font under its own license. The bytes are small; the license management is not worth a terminal picture. The JuliaMono subset under
docs/_static/does not change this: it sets the documentation’s own HTML, where a stylesheet reaches the text, and reusing it in a capture would be that same redistribution.The fallback has a cost. A stock macOS falls through to Menlo
22.0d2e1, which carries none of the mathematical symbols, Myanmar letters and emoji some spinners draw, so those resolve to proportional fonts: 6 of the 89 spinner captures draw a glyph wider than its column, and the window’s clip cuts the overflow. Menlo has no Braille either, which a capture draws as dots instead, seeBRAILLE_DOTS. Emoji stay out of reach of every monospaced font.Fitting each run to its columns instead (
lengthAdjust="spacingAndGlyphs") is no cure: it stretches a narrow glyph as readily as it squeezes a wide one, and distorts nearly a third of the runs in the committed captures by more than 6%.WATERMARK_URLdocuments the other half of this: a capture embedded with<img>never sees the page’s own@font-faceeither, so a stylesheet cannot fix this from the outside.
- click_extra.capture.presets.CAPTURE_PALETTES: dict[TerminalBackground, TerminalPalette] = {TerminalBackground.DARK: ('#292929', '#c5c8c6', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#292929'), TerminalBackground.LIGHT: ('#ffffff', '#000000', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#ffffff')}¶
Colors each chrome resolves a capture’s ANSI codes against.
A palette carries the 16 ANSI colors alongside the background and foreground, which is the other half of the job: a CLI naming
blueleaves the shade to whoever draws it, and the one that reads on white is not the one that reads on#292929.
- click_extra.capture.presets.resolve_palette(preset, background)[source]¶
The colors a capture resolves its ANSI codes against.
The preset’s palette on the given chrome, or the default terminal’s (
CAPTURE_PALETTES) when no preset dresses the capture. The one resolution rulerender()andstyle_palette()share, so the SVG and HTML formats cannot disagree on what a chrome looks like.- Parameters:
preset (
TerminalPreset|None) – terminal being pictured, orNonefor the default one.background (
TerminalBackground) – chrome the capture is drawn on.
- Return type:
- Returns:
the palette.
- click_extra.capture.presets.WINDOWS_TERMINAL_SLOTS: Final = ('black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white', 'brightBlack', 'brightRed', 'brightGreen', 'brightYellow', 'brightBlue', 'brightPurple', 'brightCyan', 'brightWhite')¶
Keys a Windows Terminal color scheme names the 16 ANSI colors under, in order.
Windows Terminal calls magenta
purple, and so does every scheme written for it.
- click_extra.capture.presets.read_palette(path)[source]¶
Read a terminal color scheme file into the palette a capture resolves against.
Two formats are read, told apart by the file’s extension. They are the ones schemes are most often shared in, and two of those iTerm2-Color-Schemes publishes each of its schemes in:
.json: a Windows Terminal scheme, one object naming each color as#rrggbbunder the keys ofWINDOWS_TERMINAL_SLOTS, plusbackgroundandforeground..itermcolors: an iTerm2 property list, each color as red, green and blue fractions underAnsi 0 ColortoAnsi 15 Color, plusBackground ColorandForeground Color.
A scheme describes the terminal and not the desktop around it, so the strip a preset paints its window’s title bar with is the background here.
Caution
An iTerm2 color in the Display P3 color space is read as sRGB, so the most saturated colors of such a scheme come out a little duller.
- Parameters:
path (
Path) – the scheme file.- Return type:
- Returns:
the palette.
- Raises:
ValueError – when the file is in neither format, misses a color, or states one in a form no color takes.
- click_extra.capture.presets.GENERIC_FONT_FAMILIES: Final = frozenset({'cursive', 'emoji', 'fangsong', 'fantasy', 'math', 'monospace', 'sans-serif', 'serif', 'system-ui', 'ui-monospace', 'ui-rounded', 'ui-sans-serif', 'ui-serif'})¶
The font families CSS names by keyword, which a stack never quotes.
- click_extra.capture.presets.parse_font_stack(value)[source]¶
Read a list of font families into the stack a capture asks for.
Families come comma-separated and best first, quoted or not, like
JetBrains Mono, Menlo. Each one holding a space is written back single-quoted, seeCAPTURE_FONT_STACK, and a stack naming no generic family closes onmonospace, which every renderer resolves.- Parameters:
value (
str) – the families, as a user writes them.- Return type:
- Returns:
the font stack, as CSS writes it.
- Raises:
ValueError – when no family is named, or one holds a character other than a letter, a digit, a space, a dot, a hyphen or an underscore. The stack lands in a stylesheet, where a quote, a brace or an angle bracket would end it early.
- click_extra.capture.presets.NO_PAINT = 'none'¶
Border or shadow value asking for none to be drawn.
SVG’s own keyword for an absent paint, so it reaches the
strokeattribute unchanged, and CSS’s for an absent shadow.
- click_extra.capture.presets.OPAQUE = 1.0¶
Opacity of a window showing nothing of what sits behind it.
Anything under it is what a terminal calls transparency: the backdrop, or the page embedding the capture, comes through the window’s body while its text, frame and title bar stay as they are.
0.0leaves the text alone on the page.
- click_extra.capture.presets.WATERMARK_INK = 'rgba(128,128,128,0.85)'¶
Color the credit line is drawn in.
The one paint in a capture that answers to neither chrome, because it is the one thing drawn outside the window: the margin is transparent, so the mark sits on whatever page embeds the image, which the capture never gets to see. A white mark suits the dark chrome it was picked for and disappears on a README; a neutral gray reads on both, and dims into a backdrop when one is painted.
- click_extra.capture.presets.DEFAULT_BORDER_WIDTH = 1¶
Thickness, in pixels, of the frame drawn around the window.
- click_extra.capture.presets.DEFAULT_RADIUS = 8¶
How round the window’s corners are, in pixels.
The radius a renderer draws on its own, which is what a terminal on a desktop looks like. Zero squares them, for a capture meant to read as a plain block.
- click_extra.capture.presets.PACKAGE_NAME = 'click-extra'¶
Name this package is distributed and credited under.
- click_extra.capture.presets.DEFAULT_WATERMARK = 'generated with click-extra'¶
Credit line every capture carries unless another one, or none, is asked for.
A capture travels: it lands on a slide, in a README, on a social card, far from the page that explains where it came from. The mark is what still says so, and carries the link back.
The line names the tool, never its release. A capture is committed beside the project that drew it and regenerated at every release, and a release number would rewrite every asset on release day for nothing but the bump.
Note
This is a default, not a fixture.
--watermark ""draws none, and any other text replaces it: a project crediting itself rather than its tooling is the expected case, not an exception.
- click_extra.capture.presets.DEFAULT_MARGIN = 48¶
Transparent pixels left around the window, on all four sides.
Room for the shadow to fall into, first of all: a filter draws outside the shape it is applied to, and anything past the image’s own box is cut. It is also what a backdrop has to show through, and what keeps the window from touching the text of the page embedding it.
- click_extra.capture.presets.DEFAULT_PADDING = 8¶
Pixels added inside the window, around the captured text.
On top of the few a renderer adds on its own (8, and 40 above for the title bar), which leaves a help screen’s first column tight against the frame.
- click_extra.capture.presets.CAPTURE_BORDERS: dict[TerminalBackground, str] = {TerminalBackground.DARK: 'rgba(255,255,255,0.35)', TerminalBackground.LIGHT: 'rgba(0,0,0,0.25)'}¶
Color the window frame is drawn in, per chrome.
The dark entry is a translucent white that reads against
#292929and against nothing else: a light capture framed with it is a white window on a white page, the shape of the terminal only guessable from its text. Each chrome names a frame its own background can show.
- click_extra.capture.presets.CAPTURE_SHADOWS: dict[TerminalBackground, str] = {TerminalBackground.DARK: 'rgba(0,0,0,0.5)', TerminalBackground.LIGHT: 'rgba(0,0,0,0.25)'}¶
Color the window’s drop shadow floods with, per chrome.
Where the frame states the window’s edge, the shadow lifts it off whatever page embeds the capture, which is the other half of not dissolving into it. A reader whose renderer drops the filter still gets the frame.
- class click_extra.capture.presets.Chrome(border=None, border_width=1, radius=None, backdrop='none', shadow=None, margin=48, padding=8, opacity=1.0, watermark='generated with click-extra', watermark_color=None)[source]¶
Bases:
objectHow the window around a capture’s text is drawn.
One value for the decoration
render(),capture(),record_and_render()andrender_snippet()all take, so its defaults live in one place. A field left atNonetakes what the capture’s background and preset draw, whichresolve()fills in.from click_extra.capture.presets import Chrome from click_extra.capture.screenshot import render svg = render(text, chrome=Chrome(margin=0, watermark=""))
- border: str | None = None¶
Color of the window’s frame.
Nonetakes the one the background can show, seeCAPTURE_BORDERS;NO_PAINTdraws none.
- radius: int | None = None¶
How round the window’s corners are, in pixels. Zero squares them.
Nonetakes the preset’s own, orDEFAULT_RADIUSwithout one.
- backdrop: str = 'none'¶
Paint filling the image behind the window, margin included.
NO_PAINTleaves it transparent.
- shadow: str | None = None¶
Color of the window’s drop shadow.
Nonetakes the background’s own, seeCAPTURE_SHADOWS;NO_PAINTdraws none.
- opacity: float = 1.0¶
How solid the window’s body is, from
OPAQUEdown to0.0.Below it, whatever the capture is laid over shows through.
- watermark: str = 'generated with click-extra'¶
Credit line drawn in the image’s bottom-right corner.
See
DEFAULT_WATERMARK. An empty string draws none.
- watermark_color: str | None = None¶
Color that line is drawn in.
NonetakesWATERMARK_INK, which reads on a page of either color.
- resolve(background, preset)[source]¶
This chrome, with every
Nonereplaced by what the capture draws.render_svg()andrender_html()take a resolved chrome, which makes this the one step between the two layers.- Parameters:
background (
TerminalBackground) – chrome the capture is headed for.preset (
TerminalPreset|None) – terminal being pictured, orNone.
- Return type:
- Returns:
a chrome carrying no
None.
- check_resolved()[source]¶
Refuse a chrome that still carries a
None.A renderer draws the values it is given, and a
Nonenames no paint and no size: onlyresolve()knows what it stands for.- Raises:
ValueError – naming each field still set to
None.- Return type:
- click_extra.capture.presets.BARE_CHROME = Chrome(border='none', border_width=1, radius=8, backdrop='none', shadow='none', margin=0, padding=0, opacity=1.0, watermark='', watermark_color='rgba(128,128,128,0.85)')¶
A resolved chrome that draws the window alone.
No frame, no shadow, no margin, no padding and no credit line: what
render_svg()andrender_html()draw when they get no chrome. A capture taken throughrender()resolves aChromeinstead, which frames the window and credits the package.