Terminal Borders That Leave Every Cell for Content


A terminal interface usually draws a panel with box-drawing characters. The frame is easy to understand, but it is still text. A top border takes a row, a side border takes a column, and nested panels pay that cost again. On a screen roughly 50 rows tall, a dashboard can spend a noticeable share of its height drawing the boundaries around its data.

Josh McKinney, a Ratatui maintainer, proposes a different primitive: draw the border on a cell’s edge while leaving the cell itself available for a character. His experimental Ghostty implementation and Ratatui demos show panels, tabs, fields, charts, and buttons using that extra room. The protocol specification is explicitly a draft, so this is a proposal to examine, not a terminal feature to assume everywhere.

The layout problem is a character problem

Unicode box drawing offers many corners, intersections, and line weights, yet each glyph occupies one entire character position. A panel with a one-cell frame makes its content rectangle narrower and shorter. Put a tab label across the top and it either displaces the line or needs another row. Put an underline directly below text in an input field and the underline needs its own row, unless an underline text attribute is good enough. A chart made from braille dots has the same collision: a gridline cannot occupy a cell that is already doing chart work.

Borders also become part of copied text. Selecting a value inside a framed interface can carry stray │ characters into the clipboard. Font choice determines how the line glyphs meet, and rounded corners expose background-colored squares when a panel sits on a different background. These are consequences of representing the border as printable content.

The proposed model draws strokes between content positions. A pane can retain its full content area; an edge is a visual property of a cell rather than a row or column of glyphs. That distinction is clearest with nested panes: the more frames a layout has, the more useful rows the old approach gives up.

Comparison of a box-drawing frame that occupies character cells with an edge-drawn frame that keeps those cells available for content.
Both layouts draw a boundary, but only the character frame changes the content grid.

A border lives with its cell

The draft treats a border set much like a background color. Each cell can have twelve independently styled segments: two halves of each of its four outside edges, plus four arms that run from the cell center. Splitting edges in half lets a border follow half-block and quadrant characters. Those are useful for compact charts and controls, although the filled shape still uses a character.

A segment has a width, color, placement, and layer. It can sit just inside the cell edge or be centered on it, and it can be painted below or above text. Optional extensions add dotted or dashed lines, double strokes, rounded joints, an outside color for rounded corners, and priority for clashes. This is enough vocabulary for a thin panel line, a colored focus outline, or a one-row button without pretending every widget should use every style.

Because the border is stored with the cell, ordinary terminal operations have coherent behavior. Scrolling moves border attributes with text. Insert and delete move them too. Erasing uses the current border pen, like clearing a cell to the current background. Reflow and scrollback can keep the visual relationship between content and its frame. A separate drawing layer would have to reconstruct much of that behavior itself.

Commands, capability checks, and fallback

The wire format uses a Device Control String, or DCS, under a cell-border namespace. Its shape is DCS 1 + b cell-border ; OP ; FIELDS ST. The 1 identifies this draft’s protocol version. A pen command changes the border set held by the cursor, so subsequently written cells receive it. Rectangle set and clear commands modify existing cells. A query asks which features the terminal supports. The smallest implementation needs the pen, rectangles, and solid strokes; other styles are advertised separately.

For example, an app can set a blue bottom-edge pen, print a field’s text, and then reset the pen. The underline belongs to those printed cells. It is not an extra line of ─ characters. A rectangle command is better for an already-rendered panel whose focus outline changes without rewriting its text.

Feature detection matters more than the terminal name. The draft tells an app to send the cell-border query followed by a standard Primary Device Attributes query. A border reply arriving first signals support. If the standard reply arrives with no border reply, the app lays out a conventional character frame and reserves the needed rows and columns. An unrecognized DCS is ignored. This also gives an older terminal a usable interface rather than an empty frame.

Application asks about cell-border support, then selects edge borders when supported or box-drawing characters when unsupported.
Capability detection happens before layout because the fallback consumes character positions.

A multiplexer is an important middle case. tmux-like programs maintain their own screen buffer and repaint it. Blindly passing border commands through could attach lines to the wrong cells. A multiplexer that does not implement the protocol should discard the commands, answer the capability check, and let the app fall back. A supporting multiplexer would need to store and redraw the attributes as part of its own cell model.

When two cells claim one line

Adjacent cells can both request a stroke on the same shared edge. Drawing both would make the seam too thick or produce competing colors. The draft resolves centered strokes at render time: higher priority wins; if tied, the wider stroke wins; if still tied, the right-hand or lower cell wins. A focused pane can therefore raise its outline priority without relying on which pane the app happened to render last. Inside-edge strokes remain separate, so they can still produce two lines where a design calls for them.

The line can also be split into half edges. That allows a boundary to meet a half-filled cell or a center arm cleanly. Rounded joints are attached to the cell quadrant they occupy, while an outside color fills the corner cut away by the arc. This addresses the mismatched-corner square seen when a rounded glyph sits over a differently colored surrounding panel. It is careful geometry rather than a new collection of Unicode characters.

The engineering bill

The prototype’s footprint is promising but not free. McKinney reports that his Ghostty change is about 1,650 lines including tests. It adds a 16-bit border ID to each cell using existing padding, so the cell structure does not grow. IDs refer to shared sets of border properties, roughly 100 bytes each. A typical interface should reuse only a few sets, but the table is not freed in the prototype; the worst case is estimated at 10–15 MB.

Rendering work is conditional on cells with borders. For a shared edge the renderer examines neighbors, so changing a row can require rebuilding adjacent rows. Straight segments are simple quads; anti-aliased rounded corners cost more. The author has not yet published proper rendering benchmarks. That makes performance, especially during fast scrolling and with many unique styles, an open question rather than a solved claim.

There is also an adoption cost. Terminal emulators, libraries, and multiplexers would all need compatible handling before an app could rely on the richer presentation across environments. The fallback is therefore part of the design, not a temporary afterthought. Copying text without border glyphs is generally welcome, though it also means a copied table will not carry its visual grid. An app that needs a pasteable table should still produce textual separators for that output.

What the experiment changes

This proposal moves a line from the text layer into the terminal’s cell model. That small shift gives a TUI more room and lets panels, underlines, chart guides, and focus outlines coexist with content. The draft goes further than a visual trick: it specifies commands, feature detection, scrolling behavior, shared-edge conflicts, and a conventional fallback.

The next useful evidence will be implementations beyond one Ghostty branch, feedback from TUI authors, and measured rendering costs. Until then, the practical lesson is to design the fallback and the compact layout together. The same interface can use cell-edge borders where available and remain legible with box-drawing characters everywhere else.

Sources

100%