Ratatui maintainer drafts terminal protocol for borders that use no cells

The author, who goes by joshka and maintains the TUI library Ratatui, describes a draft terminal protocol that draws thin lines on the edges of cells rather than using characters. A cell border is a cell attribute, like a background color, and the terminal paints it over the cell grid. So a border takes up no row or column. The author has it working as a patch to Ghostty (an earlier version was built in Rio) and has written demo apps with Ratatui. The post asks terminal and TUI authors for feedback. The author also says the post and the code behind it were written with a lot of help from AI.
The motivation is that many TUIs look alike: plain boxes on a boring background. Borders have to take up space, so they shape the panels people build. The usual tool, the Unicode Box Drawing block with 128 characters for lines, corners and joins, falls short. Because those characters are text, each line occupies a whole cell. On the author's 16-inch laptop with a readable font the terminal is about 200x50, and a layout with a couple of levels of nested panels can easily spend 6 or 8 of those 50 rows on nothing but lines. You also cannot put a line between two cells that both hold content, so there is no underline right under a text field and no outline around a button without padding. Rounded corners leave a small square of the wrong color when a panel's background differs from its surroundings, and the line's weight and position are whatever the font decides. Selecting text inside a box copies the box too, which is the familiar cleanup when pasting a TUI into Slack. Cell borders are not text, so they are never copied.
In the author's screenshots every line is a cell border. Tab labels sit on the top edge of each pane, text fields are underlined right under the text, and buttons are one row tall with rounded corners. The same app falling back to box characters loses a row and a column on every side of each pane, so the log pane shows two fewer lines and the notes wrap differently. Tab labels move inside the frame, text fields use the underline attribute, and the checkbox and buttons become brackets. The idea also works for charts: btop-style braille graphs fill every cell with dots, so a gridline or average line normally costs a row, while a cell border can sit on the cell edges between the dots. The post also shows a tiling-panes demo with menus and an about dialog.
Each cell can carry up to twelve line segments: two halves of each of its four edges, plus four arms from the center. Every segment has its own color, width, placement and style. Halving the edges lets borders line up with quadrant block characters, so a shape half a cell in from the grid can still get a neat border. That still uses a character for the fill, and the author says there may be a better way. Lines can be solid, double, dashed or dotted. Each corner and center can be square or rounded, with a configurable radius and anti-aliased arcs, and a rounded corner can name an outside color so the area beyond the arc is painted correctly. When neighboring cells both draw a line on a shared edge, they merge: the stroke with the higher priority wins, then the wider one, then the one to the right or below. A focused pane can raise its priority and keep its whole outline. The author's first attempt, "right/bottom always wins", failed when the focused pane lost half its outline to its neighbor.
On the wire, everything is one DCS string with a namespace, ESC P 1 + b cell-border ; OP ; FIELDS... ESC . The common path is a pen held in the cursor like the current background color. An app sets it, prints text, and the printed cells get the borders; SGR 0 clears the pen. There are also rectangle commands that set or clear borders on existing cells without touching the pen, and a capability query. An app sends the query followed by DA1. If the DA1 reply arrives with no cell-border reply before it, the terminal does not support the protocol, and the app falls back to box characters and reserves the space they need. Terminals that do not understand the DCS ignore it, like any unknown DCS. The minimum a terminal needs is the pen, the rectangle commands and solid strokes. Line styles, rounded joints, priority and outside colors are extension fields listed in the capability reply, and unknown fields are ignored, so more can be added later. The spec calls itself version 1, the 1 in DCS 1 + b, but the author says that means a first written-down draft, not done or stable.
The author lists prior art. DEC ruled lines in DECterm (extension 43 in the DA1 reply) draw lines around rectangles and scroll with text, but they are a separate layer that clearing the screen leaves behind, and they are always one pixel wide in the normal text color. SGR 51 to 65 (framed, encircled, overline, ideogram side lines) are on/off attributes with no color, width or joins, and there is no bottom-edge attribute. The Win32 console has per-cell grid flags for top, left and right edges, and PDCurses and X/Open curses have similar attributes (WA_TOP, WA_LEFT and others); these are the closest, but they lack a bottom edge (Win32), color, width and halves. IBM 3270 terminals can outline whole input fields. None gives each edge its own color and width. The author's first prototype in Rio (raphamorim/rio#1947) used APC. Feedback pointed out that APC is not safe to reuse, since Kermit 95 has run APC payloads as Kermit commands since the 90s, so the author moved to DCS, where structured terminal commands already live and which terminals ignore when they do not recognize it.
The post covers the awkward cases. Multiplexers such as tmux redraw panes from their own idea of the grid, so passing the sequences through would misplace borders. A multiplexer that does not know the protocol should drop them and answer DA1 itself, and apps inside then fall back to box characters. One that knows it can store borders like any attribute and redraw them. Conflicts on shared edges are resolved at render time by the priority rule, so the order the app wrote cells in does not matter. Erase, insert and delete behave as they do for background colors: erased cells pick up the current pen, and inserted or deleted lines take their borders along. Scrollback, the alternate screen and reflow mostly come free because the border lives in the cell.
On cost, the Ghostty change is about 1,650 lines, a fair chunk of it tests. Each cell gets a 16-bit border ID that fits in existing padding, so cells do not grow and a screen with no borders costs nothing extra. The IDs point into a table of distinct border sets, about 100 bytes each, shared by the whole terminal. A typical TUI uses only a handful of sets, but the table is never freed, so with all 65,535 IDs in use it reaches somewhere around 10-15 MB. Rendering does extra work only for cells with borders; each looks at its four neighbors, so changing a row also rebuilds the rows on either side. Straight lines are a few solid quads per cell, while rounded corners cost more because the anti-aliased arc is drawn as rows of small quads, roughly one per edge pixel. The author has not benchmarked any of this properly and says it is the part most in need of another set of eyes.
To try it, clone the joshka/cell-borders branch of the author's Ghostty fork (github.com/joshka/ghostty), build with Zig 0.17 and Xcode using zig build -Doptimize=ReleaseFast -Dxcframework-target=native, and open zig-out/Ghostty.app. The branch implements all of version 1, but the author has built and run it only on macOS, so the GTK and OpenGL builds are untested. A gallery script on the branch, scripts/cell-borders.py, draws the style gallery from the post (the default view, or --styles for line styles, joints and outside fill). It detects support first, so it also works as a quick check of another terminal's implementation.
Key facts
- The draft protocol is one DCS string (ESC P 1 + b cell-border ...) that sets borders as a cell attribute, so lines cost no rows or columns; each cell can carry up to twelve line segments with their own color, width, placement and style.
- It runs as a patch to Ghostty (about 1,650 lines, a fair chunk of it tests), with an earlier prototype in Rio, and Ratatui demo apps; the author asks terminal and TUI authors for feedback.
- Apps detect support by sending a query followed by DA1; if no cell-border reply arrives first, they fall back to box-drawing characters. Multiplexers that do not know the protocol should drop the sequences and answer DA1 themselves.
- Each cell gets a 16-bit border ID in existing padding; the shared table of about 100-byte border sets is never freed and tops out around 10-15 MB with all 65,535 IDs used. Performance is not yet properly benchmarked.
- Tested only on macOS; building the branch needs Zig 0.17 and Xcode, and the spec is explicitly a first draft, not a stable standard.
Why it matters
Box-drawing characters are text, so every border line eats a whole row or column. On a roughly 200x50 terminal, nested panels can burn 6 or 8 of the 50 rows on lines alone. The proposal removes that trade by making borders a cell attribute, which also lets a line sit right under a text field, around a button, or between the dots of a braille chart. Borders stop being copied with selected text, and rounded corners can name an outside color so they no longer leave a wrongly colored square. The author's argument is that this could help TUIs break out of the plain-box look. Existing partial answers (DEC ruled lines, SGR 51 to 65, Win32 and curses grid attributes) lack per-edge color and width, according to the post's prior-art survey.
Who it affects
Mainly terminal emulator authors, who would have to implement the protocol, and TUI authors and library maintainers such as those around Ratatui, who would gain layouts that do not reserve space for frames. Multiplexer authors are affected too, since tmux and similar tools redraw from their own grid and must either drop the sequences or store and redraw borders. Ordinary terminal users would notice cleaner copy and paste, because borders are never selected as text.
How to use it
Today it is for experimenters. Clone the joshka/cell-borders branch of the author's Ghostty fork, install Zig 0.17 and Xcode, and build with zig build -Doptimize=ReleaseFast -Dxcframework-target=native, then open zig-out/Ghostty.app. Inside it, run python3 scripts/cell-borders.py for the default gallery or add --styles for line styles, joints and outside fill; keys switch views. The script detects support first, so it doubles as a check of another terminal's implementation. App authors would send the capability query followed by DA1 and fall back to box characters, reserving the space they need, if no cell-border reply comes first. The spec and rationale document live on the fork.
How solid is it
It is a working implementation, not just a sketch: the author says the Ghostty branch implements all of version 1, and shows Ratatui demos of forms, tiling panes, menus, a dialog and a btop-style monitor. But everything comes from the author, who maintains Ratatui and wrote the protocol and the patch. Only the author's Ghostty patch and the earlier Rio prototype are said to implement it, and the source does not say the patch has been merged upstream or that maintainers of either terminal have responded. Version 1 is described as a first written-down draft, not stable. The post also says it and the code were written with a lot of help from AI.
Risks and caveats
The author has not benchmarked the rendering properly and calls it the part most needing review; rounded corners are drawn as rows of small quads, and changing a row rebuilds the rows either side. The border table is never freed, reaching around 10-15 MB in the worst case. Only macOS has been built and run, so GTK and OpenGL builds are untested. Multiplexers are an open adoption problem: those unaware of the protocol must drop the sequences, and apps inside them fall back to box characters. The spec is a draft, so details may change, and the author notes that APC was already abandoned for DCS after feedback. The minimum core is small, with styles, rounded joints, priority and outside colors as optional extension fields.
“I'd rather the early decisions be two way doors where possible.”
— joshka, Ratatui maintainer, on keeping the protocol's first cut small and extensible