Skip to main content

Module border

Module border 

Source
Expand description

Border rendering — styled-frame slice.

Port of ink’s render-border.ts, including the stylePiece SGR coloring that the M1 char-only port dropped (M2-C restores it).

§Design decisions

§Color (render-border.ts:7-20, 36-64)

stylePiece wraps each border piece: colorize fg (innermost) → colorize bg → dim (outermost). Per-edge fg resolves border{Edge}Color ?? borderColor; per-edge dim resolves border{Edge}DimColor ?? borderDimColor, read from Style (these are style props that flow JS→core via Box’s ...style spread). With no color and no dim, style_piece is the identity transform, so plain borders stay byte-identical.

§Per-element wrapping (render-border.ts:74-131)

Each corner+run top/bottom row is wrapped once (one SGR pair per row), and EACH vertical-bar cell is wrapped independently before the rows are joined with \n. The styled-grid write path (grid.rs) tokenizes each line with no carried SGR state, so a once-wrapped vertical strip would leave interior bars unstyled — every bar must carry its own open/close pair.

§Per-edge suppression (render-border.ts:66-69 citation)

const showTopBorder    = node.style.borderTop    !== false;
const showBottomBorder = node.style.borderBottom !== false;
const showLeftBorder   = node.style.borderLeft   !== false;
const showRightBorder  = node.style.borderRight  !== false;

A missing/true value means “show”; only explicit false suppresses. In Rust: style.border_top == Some(false) → hide; anything else → show.

§Corner handling when an edge is off (render-border.ts:74-79 citation)

let topBorder = showTopBorder
  ? (showLeftBorder ? box.topLeft : '') +
    box.top.repeat(contentWidth) +
    (showRightBorder ? box.topRight : '')
  : undefined;

Corners appear only when BOTH the edge they terminate AND the perpendicular edge are shown. When the top edge is off the entire top row is omitted (topBorder = undefined). When the left edge is off, topLeft corner is ‘’. Same logic applies to bottom/right permutations.

§Vertical border height (render-border.ts:86-95 citation)

let verticalBorderHeight = height;
if (showTopBorder)    verticalBorderHeight -= 1;
if (showBottomBorder) verticalBorderHeight -= 1;

Left/right border strings span only the interior rows (total height minus the rows consumed by top/bottom border lines).

Functions§

render_border
Draw the border of a box node into grid.