click_extra.capture.svg module¶
Draw captured terminal text as an SVG picture of a terminal window.
click_extra.capture.screenshot decides what a capture shows, then hands
the text, its palette and the resolved Chrome
to render_svg(), which lays the text out on a character grid and paints the
window around it, one layer at a time: backdrop, shadow, frame, title bar,
emphasis bands, text, cursor, credit line and animation.
The window’s geometry lives here too, since every pixel size below is the
picture’s: the title bar, the shadow’s blur and offset, the credit line’s size
and place, and the cell metrics the grid is measured in.
click_extra.capture.html draws the same window and borrows them, so the
two documents look like the same terminal. The paints and sizes a
Chrome defaults to, like
NO_PAINT and
OPAQUE, live beside it in
click_extra.capture.presets.
- click_extra.capture.svg.THold: TypeAlias¶
Pause an animation takes on its last frame, see
AUTO_HOLD.
- click_extra.capture.svg.TITLEBAR_HEIGHT = 40¶
Height, in pixels, of the strip a title and its buttons sit in.
The padding a renderer leaves above the text, which is what a window’s chrome occupies. Restated here because a capture wearing neither decoration nor caption drops the strip, and one drawn as a real terminal paints it.
- click_extra.capture.svg.SHADOW_BLUR = 6¶
Standard deviation, in pixels, of the drop shadow’s blur.
- click_extra.capture.svg.SHADOW_OFFSET = 3¶
Downward offset, in pixels, of the drop shadow.
- click_extra.capture.svg.WINDOW_PADDING = 8¶
Pixels every window keeps between its frame and its text, on three sides.
The fourth is the top, where
TITLEBAR_HEIGHTanswers instead. This is the window’s own breathing room, before thepaddinga capture may ask for on top.
- click_extra.capture.svg.WINDOW_INSET = 1¶
Pixels between the image’s edge and the window’s frame.
A stroke straddles the shape it outlines, so a frame drawn flush with the viewBox loses its outer half to the crop. Inset by more than that half and the whole line shows.
- click_extra.capture.svg.CSS_SIDE_ANGLES = {'to bottom': 180.0, 'to bottom left': 225.0, 'to bottom right': 135.0, 'to left': 270.0, 'to left bottom': 225.0, 'to left top': 315.0, 'to right': 90.0, 'to right bottom': 135.0, 'to right top': 45.0, 'to top': 0.0, 'to top left': 315.0, 'to top right': 45.0}¶
Angle each CSS side keyword names, in degrees clockwise from
to top.to bottomis what a gradient opening with no direction at all means, which is why it doubles as the default. Seegradient_svg().
- click_extra.capture.svg.TITLE_SIZE = 18¶
Height, in pixels, of the caption drawn in a window’s title bar.
- click_extra.capture.svg.WATERMARK_SIZE = 13¶
Height, in pixels, of the credit line’s glyphs.
Below the terminal’s own text, since a mark competing with the screen it credits is a mark in the way.
- click_extra.capture.svg.WATERMARK_INSET = 12¶
Pixels between the credit line and the image’s bottom-right corner.
It is drawn in the margin, the one band of a capture that carries nothing else. A capture shot with
margin=0has no such band, and the line lands on the window’s own corner instead of beside it.
- click_extra.capture.svg.WATERMARK_URL = 'https://kdeldycke.github.io/click-extra/screenshots.html'¶
Page the credit line points at, for a reader holding only the image.
A capture travels away from whatever explained it, so the mark carries the way back. Only
PACKAGE_NAMEis linked, and only where the line still names it: a project crediting itself instead has no click-extra left to point at, and gets no link rather than one pointing somewhere it did not ask for.Note
The link answers where the file is interactive: opened on its own, inlined into a page, or embedded through
<object>. An<img>draws an SVG as a picture and no click reaches inside one, which is how this documentation embeds its own captures.
- click_extra.capture.svg.CELL_HEIGHT = 20.0¶
Height of one glyph cell, in pixels, which is also the text’s font size.
- click_extra.capture.svg.FONT_ASPECT_RATIO = 0.61¶
Width-to-height ratio of the font a capture is laid out for.
Fira Code’s, the first family
CAPTURE_FONT_STACKasks for. Every monospaced fallback behind it is close enough that the grid holds, andtextLengthpins each run to its columns for the ones that are not.
- click_extra.capture.svg.CELL_WIDTH = 12.2¶
Width of one glyph cell, in pixels. One character of a monospaced terminal.
- click_extra.capture.svg.LINE_HEIGHT = 24.4¶
Vertical distance between two consecutive text baselines, in pixels.
- click_extra.capture.svg.CELL_BLEED = 0.25¶
Pixels a cell’s background is grown by, past the line it belongs to.
Two rectangles meeting on an exact boundary leave a hairline of page showing through when a renderer rounds their edges to different pixels. Overlapping them slightly is what closes that seam, and is invisible because the color painted twice is the same color.
- click_extra.capture.svg.CELL_TOP_INSET = 1.5¶
Pixels between a line’s top edge and the cell backgrounds drawn on it.
A glyph does not fill its line box: the leading sits above the tallest letter. Starting the paint just under that keeps a highlighted run reading as one block of color rather than as a band taller than the text it marks.
- click_extra.capture.svg.CURSOR_THICKNESS = 2.0¶
Pixels a cursor is drawn thick, when it is a line rather than a cell.
Both
BARandUNDERLINEare the same line turned a quarter, so one number states both. Thin enough to read as a cursor beside a glyph, thick enough to survive a renderer rounding it to whole pixels.
- click_extra.capture.svg.DEFAULT_CURSOR_SHAPE = CursorShape.BLOCK¶
Shape a cursor takes when nothing names one.
What every terminal here but Windows draws, and the shape a reader recognizes as a terminal cursor rather than as a text caret. A capture given a preset takes that terminal’s own shape instead, see
cursor.
- click_extra.capture.svg.BLOCK_ELEMENTS = {'▀': ((0, 0, 8, 4),), '▁': ((0, 7, 8, 8),), '▂': ((0, 6, 8, 8),), '▃': ((0, 5, 8, 8),), '▄': ((0, 4, 8, 8),), '▅': ((0, 3, 8, 8),), '▆': ((0, 2, 8, 8),), '▇': ((0, 1, 8, 8),), '█': ((0, 0, 8, 8),), '▉': ((0, 0, 7, 8),), '▊': ((0, 0, 6, 8),), '▋': ((0, 0, 5, 8),), '▌': ((0, 0, 4, 8),), '▍': ((0, 0, 3, 8),), '▎': ((0, 0, 2, 8),), '▏': ((0, 0, 1, 8),), '▐': ((4, 0, 8, 8),), '░': ((0, 0, 8, 8),), '▒': ((0, 0, 8, 8),), '▓': ((0, 0, 8, 8),), '▔': ((0, 0, 8, 1),), '▕': ((7, 0, 8, 8),), '▖': ((0, 4, 4, 8),), '▗': ((4, 4, 8, 8),), '▘': ((0, 0, 4, 4),), '▙': ((0, 0, 4, 8), (4, 4, 8, 8)), '▚': ((0, 0, 4, 4), (4, 4, 8, 8)), '▛': ((0, 0, 8, 4), (0, 4, 4, 8)), '▜': ((0, 0, 8, 4), (4, 4, 8, 8)), '▝': ((4, 0, 8, 4),), '▞': ((4, 0, 8, 4), (0, 4, 4, 8)), '▟': ((4, 0, 8, 4), (0, 4, 8, 8))}¶
Rectangles each Block Elements character fills on its cell.
Each rectangle is
(left, top, right, bottom), counted in eighths of the cell from its top-left corner:▁, the lower one eighth, is the finest step these characters take.block_svg()draws the rectangles in place of the glyphs, andblock_css()does in an HTML capture.A font draws these characters to its own height, not to the row’s. SF Mono
15.0d5e1draws█exactly one em tall and Menlo22.0d2e11.02 em, while a capture’s rows areLINE_HEIGHTapart, 1.22 em. Set as glyphs, two stacked rows of block art leave a band of 4.0 to 4.4 pixels between them, and stretching the glyphs would take a factor and an offset per font, which a capture cannot know. A rectangle fills its share of the cell in every renderer, whatever font the reader has.Terminals draw these characters themselves rather than take them from the font, for the same result: WezTerm with custom_block_glyphs and Alacritty with builtin_box_drawing, both on by default, and VS Code with terminal.integrated.customGlyphs under GPU acceleration.
The characters stay in the text, unpainted, see
HIDDEN_GLYPH_ATTRIBUTES. A decoration on one, like an underline, is hidden with it.
- click_extra.capture.svg.SHADE_DENSITY = {'░': 0.25, '▒': 0.5, '▓': 0.75}¶
How much of a shade character’s cell is ink.
BLOCK_ELEMENTSgives each shade the full cell. Its ink is mixed with the color behind it up front rather than thinned with opacity, for the reasonblend()gives, so a shade draws as one flat color.
- click_extra.capture.svg.BRAILLE_DOTS = ((0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (0, 3), (1, 3))¶
Where each Braille dot sits on its cell, as
(column, row)on a 2 by 4 grid.Listed in bit order: bit
nof a pattern’s offset from U+2800 raises dotn + 1. The dots number down the left column, then down the right, and the bottom row, dots 7 and 8, comes last: 8-dot Braille extends the 6-dot cell with that row.braille_svg()draws them.The rows split the line into four and the columns split the cell into two, so the dots keep one pitch across cells, and stacked rows of Braille plot one even grid.
Menlo, where a stock macOS falls through
CAPTURE_FONT_STACK, has no Braille. Its stand-in, Apple Symbols22.0d3e1, draws every pattern 0.684 em wide, 1.5 pixels wider than its column at a capture’s size. Drawn as dots, a pattern fits its cell whatever font the reader has. Terminals draw Braille themselves too: WezTerm with custom_block_glyphs and VS Code with terminal.integrated.customGlyphs.
- click_extra.capture.svg.BRAILLE_DOT_RADIUS = 0.25¶
Radius of a Braille dot, as a share of the pitch between two dots.
A quarter, so a dot is half as wide as the pitch: the proportion Apple Braille
22.0d3e1draws, a dot 248 units across on a pitch of 488.
- click_extra.capture.svg.BOX_ARMS = {'─': (0, 1, 0, 1), '━': (0, 2, 0, 2), '│': (1, 0, 1, 0), '┃': (2, 0, 2, 0), '┌': (0, 1, 1, 0), '┍': (0, 2, 1, 0), '┎': (0, 1, 2, 0), '┏': (0, 2, 2, 0), '┐': (0, 0, 1, 1), '┑': (0, 0, 1, 2), '┒': (0, 0, 2, 1), '┓': (0, 0, 2, 2), '└': (1, 1, 0, 0), '┕': (1, 2, 0, 0), '┖': (2, 1, 0, 0), '┗': (2, 2, 0, 0), '┘': (1, 0, 0, 1), '┙': (1, 0, 0, 2), '┚': (2, 0, 0, 1), '┛': (2, 0, 0, 2), '├': (1, 1, 1, 0), '┝': (1, 2, 1, 0), '┞': (2, 1, 1, 0), '┟': (1, 1, 2, 0), '┠': (2, 1, 2, 0), '┡': (2, 2, 1, 0), '┢': (1, 2, 2, 0), '┣': (2, 2, 2, 0), '┤': (1, 0, 1, 1), '┥': (1, 0, 1, 2), '┦': (2, 0, 1, 1), '┧': (1, 0, 2, 1), '┨': (2, 0, 2, 1), '┩': (2, 0, 1, 2), '┪': (1, 0, 2, 2), '┫': (2, 0, 2, 2), '┬': (0, 1, 1, 1), '┭': (0, 1, 1, 2), '┮': (0, 2, 1, 1), '┯': (0, 2, 1, 2), '┰': (0, 1, 2, 1), '┱': (0, 1, 2, 2), '┲': (0, 2, 2, 1), '┳': (0, 2, 2, 2), '┴': (1, 1, 0, 1), '┵': (1, 1, 0, 2), '┶': (1, 2, 0, 1), '┷': (1, 2, 0, 2), '┸': (2, 1, 0, 1), '┹': (2, 1, 0, 2), '┺': (2, 2, 0, 1), '┻': (2, 2, 0, 2), '┼': (1, 1, 1, 1), '┽': (1, 1, 1, 2), '┾': (1, 2, 1, 1), '┿': (1, 2, 1, 2), '╀': (2, 1, 1, 1), '╁': (1, 1, 2, 1), '╂': (2, 1, 2, 1), '╃': (2, 1, 1, 2), '╄': (2, 2, 1, 1), '╅': (1, 1, 2, 2), '╆': (1, 2, 2, 1), '╇': (2, 2, 1, 2), '╈': (1, 2, 2, 2), '╉': (2, 1, 2, 2), '╊': (2, 2, 2, 1), '╋': (2, 2, 2, 2), '═': (0, 3, 0, 3), '║': (3, 0, 3, 0), '╒': (0, 3, 1, 0), '╓': (0, 1, 3, 0), '╔': (0, 3, 3, 0), '╕': (0, 0, 1, 3), '╖': (0, 0, 3, 1), '╗': (0, 0, 3, 3), '╘': (1, 3, 0, 0), '╙': (3, 1, 0, 0), '╚': (3, 3, 0, 0), '╛': (1, 0, 0, 3), '╜': (3, 0, 0, 1), '╝': (3, 0, 0, 3), '╞': (1, 3, 1, 0), '╟': (3, 1, 3, 0), '╠': (3, 3, 3, 0), '╡': (1, 0, 1, 3), '╢': (3, 0, 3, 1), '╣': (3, 0, 3, 3), '╤': (0, 3, 1, 3), '╥': (0, 1, 3, 1), '╦': (0, 3, 3, 3), '╧': (1, 3, 0, 3), '╨': (3, 1, 0, 1), '╩': (3, 3, 0, 3), '╪': (1, 3, 1, 3), '╫': (3, 1, 3, 1), '╬': (3, 3, 3, 3), '╴': (0, 0, 0, 1), '╵': (1, 0, 0, 0), '╶': (0, 1, 0, 0), '╷': (0, 0, 1, 0), '╸': (0, 0, 0, 2), '╹': (2, 0, 0, 0), '╺': (0, 2, 0, 0), '╻': (0, 0, 2, 0), '╼': (0, 2, 0, 1), '╽': (1, 0, 2, 0), '╾': (0, 1, 0, 2), '╿': (2, 0, 1, 0)}¶
Arms of each Box Drawing line, as their
(up, right, down, left)weights.0draws no arm,1a light one,2a heavy one and3a double one: the weights the character’s Unicode name lists.box_svg()draws each arm from its cell’s edge toward the middle, and works out where two arms’ strokes meet.As glyphs, two of these meet wherever the font and the renderer place them, a fraction of a pixel off the grid, and a table’s rule shows a seam or a kink at every join: rich#2536, which its maintainer answers takes drawn shapes. Terminals draw these characters themselves: WezTerm with custom_block_glyphs, Alacritty with builtin_box_drawing and VS Code with terminal.integrated.customGlyphs.
- click_extra.capture.svg.BOX_STROKES = {1: ((-1, 1),), 2: ((-2, 2),), 3: ((-3, -1), (1, 3))}¶
Where the strokes of a light, heavy and double arm sit across it.
Counted from the cell’s middle line, in sixteenths of its width or thirty-seconds of its height: one unit on both axes, a row being twice as tall as a column is wide. A light stroke is two units thick, 0.076 em, close to Menlo
22.0d2e1’s 0.078 em. A heavy one is twice that, and a double one is two light strokes a light stroke apart, as Menlo draws them.
- click_extra.capture.svg.BOX_DASHES = {'┄': (False, 1, 3), '┅': (False, 2, 3), '┆': (True, 1, 3), '┇': (True, 2, 3), '┈': (False, 1, 4), '┉': (False, 2, 4), '┊': (True, 1, 4), '┋': (True, 2, 4), '╌': (False, 1, 2), '╍': (False, 2, 2), '╎': (True, 1, 2), '╏': (True, 2, 2)}¶
Dashed Box Drawing lines, as whether each runs down, its weight and its dashes.
A dash covers two thirds of its share of the cell and leaves the rest as a gap split between its two ends, so dashes keep one pitch across cells.
- click_extra.capture.svg.BOX_CURVES = {'╭': 'M16,16 A8,8 0 0,0 8,24 L8,32', '╮': 'M0,16 A8,8 0 0,1 8,24 L8,32', '╯': 'M8,0 L8,8 A8,8 0 0,1 0,16', '╰': 'M8,0 L8,8 A8,8 0 0,0 16,16', '╱': 'M16,0 L0,32', '╲': 'M0,0 L16,32', '╳': 'M16,0 L0,32 M0,0 L16,32'}¶
Arcs and diagonals of Box Drawing, as SVG path data on a 16 by 32 cell.
Drawn as a light stroke, see
BOX_STROKES. An arc turns on a radius of half the cell’s width, so it meets the straight arms of its neighbors.
- click_extra.capture.svg.DIM_RATIO = 0.4¶
How far a
dimrun’s ink is mixed toward the background, seeblend().
- click_extra.capture.svg.EMPHASIS_RATIO = 0.16¶
How far an emphasized line’s band is mixed from the background toward the ink.
Mixed rather than stated outright, so one number answers for every chrome: a band a shade lighter than a dark terminal is a shade darker than a light one, and both read as the same emphasis. Far enough to find the line at a glance, near enough to leave its text the thing being read.
- click_extra.capture.svg.HIDDEN_FRAME_ATTRIBUTES = ' visibility="hidden" opacity="0"'¶
How an animated capture hides the frames its still is not made of.
Presentation attributes rather than a stylesheet rule, so a renderer reading no CSS still shows one picture instead of every frame at once. A CSS animation outranks a presentation attribute, so
frame_animation_css()restores both together and the two mechanisms never disagree.Caution
Neither property is redundant.
visibilityalone satisfies a browser,librsvgand macOS Quick Look’s thumbnailer, but two other readers ignore it and draw every frame on top of the last: a git client’s SVG diff view, and macOS Finder’s preview pane, a different code path from the thumbnailer. Both honoropacity, so each property covers a reader the other misses, and dropping either takes a class of reader with it.
- click_extra.capture.svg.HIDDEN_GLYPH_ATTRIBUTES = ' opacity="0"'¶
How a run drawn as shapes keeps its characters without painting them.
Kept as text, the characters still reach a reader copying the capture’s text, and whatever rebuilds the terminal’s lines from it.
opacity, because every reader honors it, seeHIDDEN_FRAME_ATTRIBUTES.fillwould lose to the run’s class, which sets it in the stylesheet, and AppKit’sNSImageignoresfill-opacityon text: macOS Finder’s preview pane and a git client’s SVG diff view then draw each glyph over its own shapes.
- click_extra.capture.svg.ANIMATION_METADATA_RE = re.compile('<!-- @recording (?P<fields>[^>]*?) -->')¶
The line an animated capture states its own identity on.
Written beside the
@generatedline, and read back by whatever has to decide whether a freshly drawn animation is the one already on disk. Holding the answer in the file is what spares that decision from parsing an SVG back into frames.
- click_extra.capture.svg.FRAME_TIMING_FUNCTION = 'step-end'¶
How an animated capture moves between two frames: it does not.
A terminal repaints a whole cell at once, so a capture of one has nothing to interpolate.
step-endholds each keyframe’s value until the next one is reached, which turns a percentage ladder into discrete frames and lets every frame state its own window. That is what carries a recording, whose frames each last as long as the terminal held them, on the same machinery as a spinner, whose frames are all the same length.
- click_extra.capture.svg.REDUCED_MOTION_QUERY = '@media (prefers-reduced-motion: no-preference)'¶
Guard every animation rule an animated capture emits sits behind.
click_extra.accessibilitycounts an endlessly repeating spinner among the things--accessibleexists to lower, and an image looping forever on a documentation page is the same imposition on a reader who asked their system for less motion. Outside the guard the first frame stays visible and the rest stay hidden, which is the picture a renderer that reads no CSS animation already gets, so honoring the preference costs a media query and no second code path.
- click_extra.capture.svg.AUTO_HOLD: Literal['auto'] = 'auto'¶
Hold asking for the pause the final screen’s own density decides.
Resolved by
auto_hold(): the busier the closing screen, the longer the loop pauses on it before starting over. A fixed number serves an animation whose ending the author has seen; this serves one whose ending changes with every retake, like a recorded command whose closing report grows with what there is to report.
- click_extra.capture.svg.AUTO_HOLD_SECONDS_PER_LINE = 0.25¶
Seconds
auto_hold()grants per populated line of the final screen.A scanning rate rather than a reading one: terminal output is tables and listings, which a reader sweeps at a few lines a second rather than reads word by word.
- click_extra.capture.svg.AUTO_HOLD_MIN = 2.0¶
Shortest pause
auto_hold()answers.Even a one-line outcome deserves a beat before the loop swallows it.
- click_extra.capture.svg.AUTO_HOLD_MAX = 30.0¶
Longest pause
auto_hold()answers.Past this, a looping animation reads as a still that never moves: whoever needs longer than half a minute on one screen wants the still, not the loop.
- click_extra.capture.svg.auto_hold(text)[source]¶
Seconds a reader needs on a closing screen, from how much it shows.
Counts the populated lines of text (ANSI escapes stripped, blank rows ignored) and grants
AUTO_HOLD_SECONDS_PER_LINEfor each, clamped betweenAUTO_HOLD_MINandAUTO_HOLD_MAX. Lines rather than words, because terminal output is mostly tables whose box-drawing rows would drown a word count without adding anything to read.
- click_extra.capture.svg.parse_pause(value)[source]¶
Read a pause written as text into seconds, zero included.
- Parameters:
value (
str) – the text.- Return type:
- Returns:
the pause, in seconds.
- Raises:
ValueError – when the text is not a number, or is negative.
- click_extra.capture.svg.parse_hold(value)[source]¶
Read a hold written as text into seconds, or into
auto.AUTO_HOLDscales the pause to the final frame’s own line count, seeauto_hold().- Parameters:
value (
str) – the text, a number of seconds or the wordauto.- Return type:
- Returns:
the hold.
- Raises:
ValueError – when the text is neither, or names a negative pause.
- click_extra.capture.svg.blend(color, into, ratio)[source]¶
Mix
colortowardinto, the way a terminal fades dim text.SVG has no dim, and thinning the glyphs with
opacitywould let whatever sits behind the capture show through them. Mixing the two colors up front keeps the text opaque and lands the same shade.
- click_extra.capture.svg.emphasis_paint(palette)[source]¶
The color an emphasized line’s band is painted, on
palette.EMPHASIS_RATIOof the way from the terminal’s background toward its ink, seeblend().- Parameters:
palette (
TerminalPalette) – the terminal colors the capture is drawn with.- Return type:
- Returns:
the band’s color, as
#rrggbb.
- click_extra.capture.svg.palette_color(color, palette)[source]¶
Resolve any color a
Stylecarries to a hex string.The 16 named and indexed ANSI slots are not colors, they are names: a terminal decides what its
redlooks like, and a capture has no terminal, so they answer topalette. Every other form a style can carry (a 24-bit triplet, a 256-cube index, a hex string) already states its own color and passes through.- Parameters:
palette (
TerminalPalette) – the terminal colors to resolve names against.
- Return type:
- Returns:
the color, as
#rrggbb.- Raises:
ValueError – when the value names no color.
- click_extra.capture.svg.style_rules(style, palette)[source]¶
Compile a style to the CSS an SVG text run is drawn with.
- Parameters:
style (
Style) – the run’s style, assplit_ansi()yields it.palette (
TerminalPalette) – the terminal colors to resolve names against.
- Return type:
- Returns:
the CSS declarations, semicolon-separated.
- click_extra.capture.svg.cursor_cell(picture, columns)[source]¶
Where a terminal left its cursor on the screen a capture pictures.
A command printing line by line leaves its cursor after the last thing it wrote, so the cursor stands at the end of the last row a
TerminalScreenjoins with newlines. A picture closing on a newline therefore carries an empty last row, and the cursor lands on it at column zero, which is where a terminal puts it.Note
Derived rather than recorded, and exactly rather than nearly: the position is a property of the text a screen holds, so it survives a frame travelling as a bare string and costs the recorder no second channel to carry it on.
Todo
Carry each frame’s cursor position and visibility beside its text once a recording of a full-screen program asks for a cursor. Such a program moves and hides its cursor anywhere on the screen, which the end of the text does not say, so the cursor drawn today stands after its last row.
- Parameters:
- Return type:
- Returns:
the cursor’s row and column, both counted from zero, or
Nonefor a screen showing nothing. The blank beat closing an animation’s cycle is the one such screen, and an empty terminal shows no cursor.
- click_extra.capture.svg.gradient_svg(value, unique_id, width, height)[source]¶
Translate a CSS gradient into the paint server SVG draws it with.
An SVG
filltakes a paint: a color, or a reference to a gradient declared as an element of its own. The syntax a page’s CSS carries,linear-gradient(135deg, #ff9a9e, #fad0c4), means nothing to it, and a capture handed one would come out unpainted. So the CSS is read here and re-emitted as the element SVG does understand, which is what lets the same--backdropvalue serve both formats.Understood:
linear-gradientopening with an optional angle (135deg) or side keyword (to bottom right, seeCSS_SIDE_ANGLES), andradial-gradient, both followed by two or more color stops, each pinnable at a percentage. Anything else returnsNoneand is left alone, being a plain color as far as this is concerned.The gradient is placed in user space, which is what makes it exact rather than approximated: the CSS line runs through the image’s center at the given angle, and is as long as the box measures along it (
|W·sinθ| + |H·cosθ|), while a radial one reaches the farthest corner.- Parameters:
- Return type:
- Returns:
the
<defs>markup and thefillvalue referencing it, orNonewhen the value is not a gradient this understands.
- click_extra.capture.svg.titlebar_strip(left, top, width, *, paint, radius)[source]¶
Paint the strip a terminal seats its title and buttons in.
A capture leaves that strip the color of the terminal itself, where a real window carries a chrome of its own: the strip is what a reader’s eye reads as the top of a window rather than as the first line of output.
Drawn as a path rather than a rectangle because only its top corners follow the window’s own rounding; the bottom two meet the text and stay square.
- Parameters:
- Return type:
- Returns:
the SVG markup.
- click_extra.capture.svg.credit_markup(text, url, link, *, escape)[source]¶
Write a credit line as markup, the package name it credits linked.
The one part of the line worth pointing anywhere is the name, so both documents link that and leave the rest as prose. A line naming no package, or given no URL, is the escaped text and nothing more: a custom credit has nothing to link.
- Parameters:
text (
str) – the credit line.url (
str) – where the package name points. Empty links nothing.link (
Callable[[str,str],str]) – draws the anchor around the name, from the URL and the raw name. It escapes both for the document it writes.escape (
Callable[[str],str]) – how the rest of the line is escaped for that document.
- Return type:
- Returns:
the markup.
- click_extra.capture.svg.watermark_svg(text, *, width, height, paint, font_stack="'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace", url='https://kdeldycke.github.io/click-extra/screenshots.html')[source]¶
Draw the credit line in the image’s bottom-right corner.
Placed in the margin rather than over the terminal, which is what keeps it from covering a line of output: a capture is a picture of text, and a mark crossing that text costs the reader the thing being shown.
Carries a
watermarkclass, so a reader taking a capture apart can tell the one run the renderer never captured from the ones it did.The package name is wrapped in a link, see
WATERMARK_URLandcredit_markup().- Parameters:
text (
str) – the credit to draw. Empty draws nothing.width (
float) – width of the whole image, in pixels.height (
float) – its height, in pixels.paint (
str) – color to draw the text in, alpha included.font_stack (
str) – fonts it is set in, the capture’s own.url (
str) – where the package name points. Empty links nothing.
- Return type:
- Returns:
the SVG markup, empty when there is nothing to draw.
- click_extra.capture.svg.window_buttons(buttons, *, width, color, font_stack="'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace")[source]¶
Draw a title bar’s decorations, as the terminal being mimicked draws them.
Two conventions, and a window carries one or the other: macOS fills round buttons on the left, Windows and GNOME set glyphs against the right edge. Both are placed in the window’s own coordinates, so they follow it wherever the frame moves it.
- Parameters:
buttons (
WindowButtons) – which decorations to draw.width (
float) – width of the window they are drawn in, in pixels.color (
str) – paint for the glyphs. Circles carry their own.font_stack (
str) – fonts the glyphs are set in, the window’s own.
- Return type:
- Returns:
the SVG markup, empty when the window wears none.
- click_extra.capture.svg.cursor_svg(cursor, row, column, paint, unique_id)[source]¶
Draw a terminal’s cursor on the cell it stands on.
Emitted as part of that row’s cell backgrounds rather than as a layer of its own, which is what puts it under the glyphs and hands it to the machinery already deciding which rows move between frames. A row whose cursor never stirs is then drawn once for the whole animation, and a row that moves carries its cursor along at no charge. It is also why an animation typing a command line needs no caret of its own: the cursor follows the text.
Note
The cursor is never drawn over a glyph, so a block shape covering one is not a case to answer.
cursor_cell()puts it at the end of a row, which is past everything written on it.- Parameters:
- Return type:
- Returns:
the SVG source for the cursor.
- click_extra.capture.svg.column_segments(text, column)[source]¶
Cut a run of text into the columns it actually occupies.
A run carries its own padding: a help screen’s –count INTEGER Number of greetings. is one styled run holding two columns and the gutter between them. Drawn as a single element, the second column only lands where it belongs if the renderer honors
textLengthand resolves the font, because the gutter’s width is being paid for in glyphs.librsvgdoes neither, and the columns collapse onto each other.Cutting the run at its gutters and giving each piece its own offset asks nothing of the renderer but to draw glyphs at coordinates.
- click_extra.capture.svg.glyph_offsets(text, column)[source]¶
Place a piece of text on the grid, as the attributes SVG reads.
A right-to-left piece is pinned by its offset alone: it is reordered and shaped by whoever draws it, and holding it to a width fights that.
- click_extra.capture.svg.shape_runs(text, column)[source]¶
Cut a column’s text into its runs of shapes and the text between.
A run of Box Drawing, Block Elements and Braille patterns is drawn as shapes by
shape_svg(), and the text between as glyphs. That text is trimmed of the blanks at either end, which its offset pays for instead, ascolumn_segments()does for a column.
- click_extra.capture.svg.block_svg(text, column, top, ink, paper)[source]¶
Draw a run of Block Elements as the rectangles they name.
Each character fills its share of its cell, see
BLOCK_ELEMENTS. Neighbors sharing a band and a paint merge into one rectangle, so a bar of█is one shape rather than one per cell. A rectangle reaching the bottom of its cell takes theCELL_BLEEDa background takes, which closes the seam with the row below.- Parameters:
text (
str) – the run, Block Elements only.column (
int) – the terminal column it starts on.top (
float) – where the row’s cells start, seeCELL_TOP_INSET.ink (
str) – color the shapes are drawn in, as#rrggbb.paper (
str) – color behind them, as#rrggbb, which a shade mixes its ink with, seeSHADE_DENSITY.
- Return type:
- Returns:
the SVG markup.
- click_extra.capture.svg.braille_dots(char)[source]¶
Where the dots a Braille pattern raises sit on its cell.
- click_extra.capture.svg.braille_svg(text, column, top, ink)[source]¶
Draw a run of Braille patterns as the dots they raise.
- click_extra.capture.svg.box_strokes(char)[source]¶
The rectangles a Box Drawing line or dash fills on its cell.
Each is
(vertical, low, high, start, end): whether the stroke runs down, then its span across and its span along, in the units ofBOX_STROKES, on a cell 16 wide and 32 tall. Strokes on one line are merged, so a straight line is one rectangle.A stroke runs from its cell’s edge toward the middle, and stops where its arm meets the arms across it, the way Menlo
22.0d2e1draws each join:A line passing straight through runs on into its other half, across the gap of a double line if it meets one, as in
╪.A single line ending on a double line that passes through stops at its nearer stroke, as in
╤.A stroke of a double line stops at the nearer stroke of the arm on its side, as the inner corner of
╔does.Any other stroke runs to the far edge of the arms across it, which fills the corner it turns, as the outer corner of
╔does.
- click_extra.capture.svg.box_svg(text, column, top, ink)[source]¶
Draw a run of Box Drawing as the lines it names.
Lines and dashes are rectangles, see
box_strokes(), and a stroke running on into the next cell merges with it, so a table’s rule is one shape. Arcs and diagonals are paths, seeBOX_CURVES. A vertical stroke reaching the bottom of its cell takes theCELL_BLEEDa background takes, which closes the seam with the row below.
- click_extra.capture.svg.shape_svg(text, column, top, ink, paper)[source]¶
Draw a run of shapes: lines, rectangles and dots.
Box Drawing is drawn by
box_svg(), Block Elements byblock_svg()and Braille patterns bybraille_svg().- Parameters:
text (
str) – the run, seeshape_runs().column (
int) – the terminal column it starts on.top (
float) – where the row’s cells start, seeCELL_TOP_INSET.ink (
str) – color the shapes are drawn in, as#rrggbb.paper (
str) – color behind them, as#rrggbb, seeblock_svg().
- Return type:
- Returns:
the SVG markup.
- click_extra.capture.svg.animation_digest(frames, durations)[source]¶
Fingerprint what an animation is, rather than how it happened to run.
Two recordings of one unchanged command are never byte-identical: the durations are wall-clock, so they answer to how busy the machine was. Quantizing settles the ordinary jitter and cannot settle a frame the scheduler dropped, which leaves a shorter sequence of the same frames.
So the fingerprint covers the frames a cycle holds and the beat it holds them on, not the order or the count. A dropped frame changes neither, and a command whose output actually changed changes the first.
Note
This is what lets a rebuild leave an unchanged asset alone instead of rewriting it, see
ANIMATION_METADATA_RE. It is a freshness check and never a security one: a digest saying two animations match is a statement about the pixels, made by the same process that drew them.
- click_extra.capture.svg.animation_metadata(svg)[source]¶
Read back what an animated capture states about itself.
- click_extra.capture.svg.frame_animation_css(unique_id, durations, shared=())[source]¶
Time an animated capture’s frames into CSS animation rules.
Every frame is shown for its own slice of one cycle, so a recording whose frames each lasted as long as the terminal held them rides the same machinery as a spinner whose frames are all one interval. A group several frames share is shown over each of their slices.
Note
Each boundary is computed once and handed to both the frame that ends on it and the frame that starts there. Rounding the two sides of one instant separately is what opens a gap, which the animation shows as a blank flash, or an overlap, which it shows as two frames drawn at once.
Every rule sits behind
REDUCED_MOTION_QUERY, and nothing else here hides anything: the frames a still is not made of carryHIDDEN_FRAME_ATTRIBUTESas presentation attributes instead. A CSS animation outranks a presentation attribute, so the two never argue, and putting the hiding outside CSS altogether is what keeps a renderer reading no stylesheet from drawing every frame on top of the last. The keyframes restore both properties those attributes set, for the same reason.- Parameters:
- Return type:
- Returns:
the stylesheet fragment, indented to sit in a
<style>block.- Raises:
ValueError – when a frame is given a duration that is not positive.
- click_extra.capture.svg.blink_css(unique_id, period)[source]¶
Time a cursor’s blink into a CSS animation rule.
One keyframe set and one rule for the whole document, however many frames it holds: a terminal has one cursor, and every frame’s copy of it therefore lights and darkens together. It steps like a frame does, being lit or dark with nothing in between, see
FRAME_TIMING_FUNCTION.Note
The blink dims
opacityand never touchesvisibility. A cursor sits inside the group of the frame it belongs to, and that group is hidden by both properties at once, seeHIDDEN_FRAME_ATTRIBUTES. Opacity multiplies down into the group, so a hidden frame’s cursor stays hidden; a rule restoringvisibilitywould instead override the inherited value and show every frame’s cursor at once.The rule sits behind
REDUCED_MOTION_QUERY, which leaves the cursor lit and still for a reader who asked their system for less motion.- Parameters:
- Return type:
- Returns:
the stylesheet fragment, indented to sit in a
<style>block.- Raises:
ValueError – when the period is not positive.
- click_extra.capture.svg.render_svg(text='', *, columns, title='', unique_id=None, frames=None, interval=None, hold=0.0, blank=0.0, speed=1.0, emphasize=(), cursor=None, wrap_marker='', palette=('#292929', '#c5c8c6', ('#2e3436', '#cc0000', '#4e9a06', '#c4a000', '#3465a4', '#75507b', '#06989a', '#d3d7cf', '#555753', '#ef2929', '#8ae234', '#fce94f', '#729fcf', '#ad7fa8', '#34e2e2', '#eeeeec'), '#292929'), font_stack="'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace", 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)'), buttons=(('#ff5f57', '#febc2e', '#28c840'), ''), buttons_color=None, titlebar='none', collapse_titlebar=False)[source]¶
Draw captured terminal text as a picture of a terminal window.
A terminal is a fixed grid of identically-sized cells, which is what makes this arithmetic rather than typesetting:
grid()says which cell each run of same-styled characters starts on, and every coordinate below is that column timesCELL_WIDTH.Two primitives draw everything. A
<rect>fills the cells behind a run that carries a background, and a<text>draws its glyphs, pinned to its columns withtextLengthso the layout survives a reader who does not have the font. Box Drawing, Block Elements and Braille patterns are the exception: drawn as shapes byshape_svg(), and kept, unpainted, as text.Note
A run’s padding is left out of its
<text>and paid for in thexoffset instead. Written the other way, a column only lands where it belongs if the glyphs are exactly the width assumed here, which asks the renderer to both honortextLengthand resolve the font. A web browser does both.librsvg(and through itrsvg-convertand ImageMagick) ignorestextLength, and a file manager, a git client or a thumbnailer commonly falls back to a proportional font. Starting each run on its own column asks neither.Passing
framesdraws an animation instead of a still. The window, its caption and its clip path are drawn once and every frame is stacked inside them, so the frames differ in nothing but their text, and one stylesheet covers the lot: a color two frames share is one rule, and a frame cannot name a class the document never defines. Frames are hidden byframe_animation_css()in turn, leaving the last one that draws anything visible wherever the animation does not run.Note
Everything a frame carries is namespaced by
unique_id, keyframes included, so two animations inlined into one HTML page keep their own timing. Sharing a selector between them is what makes the shorter one run on the longer one’s clock and blank out for the frames it does not have.- Parameters:
text (
str) – captured output, ANSI escape sequences included. The whole picture whenframesis left out, and unused when it is given.columns (
int) – width of the terminal, in characters.title (
str) – caption drawn in the window’s title bar. Empty draws none.unique_id (
str|None) – prefix namespacing this document’s CSS classes and element IDs, seerender(). Derived from the content when not given.frames (
Sequence[str] |None) – the animation’s frames, each captured text, in order. A single frame draws the same stilltextwould.interval (
float|Sequence[float] |None) – seconds each frame is shown. One number times every frame alike, which is what a spinner asks for; a sequence gives each frame its own, which is what a recording asks for. Required alongsideframes.hold (
float|Literal['auto']) – extra seconds the last frame stays up before the animation starts over. An animation that ends somewhere (a trail filled in, a bar run out, an outcome landed) is worth reading, and a loop that restarts the instant it arrives never lets anyone. A spinner turning in place ends nowhere, so it wants none of this and defaults to none.AUTO_HOLDscales the pause to the final frame’s own line count, seeauto_hold().blank (
float) – seconds of empty screen closing the cycle, afterhold. A loop that jumps from its last frame back to its first reads as one long animation doing something odd; an empty beat says plainly that this is where it starts over. Never the frame a still falls back to.speed (
float) – how much faster to play than it was recorded, so2halves every frame’s time and0.5doubles it.holdandblankare stated in real seconds and are not scaled: they are how long a reader is given, not part of what is being replayed.emphasize (
Sequence[int]) – lines to draw a band behind, counted from1the way:emphasize-lines:counts them. A band runs the full width of the window rather than of the text, the row being what is emphasized. In an animation it appears with the frame that first draws the row it marks, which is also when a gutter would first number that row, and it is gone again wherever the row is.cursor (
Cursor|None) – the terminal cursor to draw, seeCursor.Nonedraws none. Where it stands is read off each frame’s own text, seecursor_cell(), so an animation carries it from screen to screen on its own. A cursor landing under the last line of output grows the window by that line, the way a terminal’s does.wrap_marker (
str) – characters closing each row a fold cut short, seegrid(). Empty folds silently, the way a terminal does.palette (
TerminalPalette) – terminal colors the capture’s ANSI codes resolve against.font_stack (
str) – fonts the text is set in, best first.chrome (
Chrome) – the window around the text, resolved, seeresolve(): its frame, corners, backdrop, shadow, margin, padding, opacity and credit line. Itsbackdroptakes a CSS gradient too, seegradient_svg(). Itsopacitythins the window’s body alone: the frame, the title bar and the text keep their own paint. Defaults toBARE_CHROME.buttons (
WindowButtons) – decorations drawn in the title bar.buttons_color (
str|None) – paint for the glyph decorations. Circles carry their own colors.Nonetakes the palette’s foreground.titlebar (
str) – paint for the strip the title and buttons sit in.NO_PAINTleaves it the terminal’s own color.collapse_titlebar (
bool) – drop that strip, closing the window over the first line of text. For a capture wearing neither decoration nor caption.
- Return type:
- Returns:
the SVG source.
- Raises:
ValueError – when
chromeis not resolved, whenframesis given without aninterval, when the two disagree on how many frames there are, when no frame is given, whenholdorblankis negative, whenemphasizenames a line the capture does not have, or when acursoris given a negative blink.