{"article":{"slug":"terminal-borders-that-dont-cost-a-cell","title":"Terminal borders that don't cost a cell","subtitle":null,"summary":"Ratatui maintainer Josh McKinney proposes a terminal protocol for thin lines drawn on cell edges, so borders, rounded corners and gridlines don't consume rows or columns, with a working Ghostty prototype and Ratatui demos.","content_type":"blog_post","language":"en","canonical_url":"https://www.joshka.net/cell-borders/","author":{"name":"Josh McKinney","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Joshka.net","url":"https://www.joshka.net/","listing_slug":null,"listing":null},"topics":[{"name":"developer-tools","slug":"developer-tools","url":"https://listedarticles.com/topics/developer-tools"},{"name":"open-source","slug":"open-source","url":"https://listedarticles.com/topics/open-source"},{"name":"design","slug":"design","url":"https://listedarticles.com/topics/design"},{"name":"rust","slug":"rust","url":"https://listedarticles.com/topics/rust"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":2681,"reading_minutes":12,"published_at":"2026-11-13T00:00:00.000Z","added_at":"2026-11-13T14:10:14.182Z","updated_at":"2026-11-13T14:10:14.182Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/terminal-borders-that-dont-cost-a-cell","markdown_url":"https://listedarticles.com/articles/terminal-borders-that-dont-cost-a-cell.md","example":false,"citation":"Josh McKinney, Joshka.net. \"Terminal borders that don't cost a cell.\" 13 Nov 2026. https://www.joshka.net/cell-borders/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://www.joshka.net/cell-borders/"},"body_markdown":"# [Terminal borders that don't cost a cell](https://www.joshka.net/cell-borders/)\n\n2026-11-13\n\n :: tags: \n[#Ghostty](https://www.joshka.net/tags/ghostty/) \n[#Ratatui](https://www.joshka.net/tags/ratatui/) \n[#TUI](https://www.joshka.net/tags/tui/) \n[#Terminals](https://www.joshka.net/tags/terminals/)\n\n*This post (and the code behind it) was written with a lot of help from AI. I'm not going to\napologize for that. If that bothers you, feel free to close the tab.*\n\nI maintain [Ratatui](https://ratatui.rs), so I see a lot of the TUIs people build. Many of them end up looking fairly\nsame-ish: plain boxes on a boring background, missing a bunch of the things that good design in\nother mediums brings us.\n\nBorders are part of the problem. They have to take up space, so they become part of the panels\npeople want to build. One option is to drop them and just use color, but borders are really nice\nfor delineating and surrounding things. There are lots of ways to sort of get borders in a\nterminal, but none that are 100% good. I've drawn enough `┌──┐` by hand to have opinions about\nthis.\n\nThe usual way is the Unicode Box Drawing block, which has 128 characters for lines, corners and\njoins. Somehow that's still not enough:\n\n[![The Unicode Box Drawing block, U+2500 to U+257F, rendered in Ghostty](https://www.joshka.net/cell-borders/box-drawing-block.png)](https://www.joshka.net/cell-borders/box-drawing-block.png)\n\nSo I've been working on a terminal protocol that draws thin lines on the edges of cells instead.\nI've got it working as [a patch to Ghostty](https://github.com/joshka/ghostty/tree/joshka/cell-borders) (and [an earlier version in\nRio](https://github.com/raphamorim/rio/pull/1947) before that), and\nI've built demo apps for it with Ratatui. I'd like feedback from\nterminal and TUI authors.\n\n[![A tiling window manager demo built with Ratatui, using cell borders for panes, tabs, form fields and buttons](https://www.joshka.net/cell-borders/panes.png)](https://www.joshka.net/cell-borders/panes.png)\n\nEvery line in that screenshot is a cell border. None of them use up a row or column. The tab\nlabels sit on the top edge of each pane, the text fields are underlined right under the text, and\nthe buttons are one row tall and rounded.\n\nHere's the same app in a terminal without cell borders, falling back to box-drawing characters:\n\n[![The same demo drawn with box-drawing characters](https://www.joshka.net/cell-borders/panes-box.png)](https://www.joshka.net/cell-borders/panes-box.png)\n\nEach pane loses a row and a column on every side, so the log pane shows two fewer lines and the\nnotes wrap differently. The tab labels move inside the frame. The text fields use the underline\nattribute instead, and the checkbox and buttons turn into brackets.\n\n## What I'd use it for\n\n- Borders, obviously. Panes and panels that don't eat a row and column on every side.\n- Menus and popups that sit on top of other content and still look like they're on top.\n- Panel style apps, where the layout is a set of regions that each want an edge.\n- Widgets like text fields, buttons and checkboxes, which want a line right up against their text.\n- Making things look neater in general. A border on the outer edge of a panel's background looks\n  a lot cleaner, and text can run right up to it.\n\n### Up close\n\nThe settings form, with cell borders and then with the box-drawing fallback:\n\n[![A form with underlined text fields, a checkbox and rounded buttons drawn with cell borders](https://www.joshka.net/cell-borders/zoom-form.png)](https://www.joshka.net/cell-borders/zoom-form.png)\n\n[![The same form with the underline attribute and bracketed buttons](https://www.joshka.net/cell-borders/zoom-form-box.png)](https://www.joshka.net/cell-borders/zoom-form-box.png)\n\nThe tabs are the same story. With cell borders they sit on the pane's top edge. With box\ncharacters they need their own row inside the frame:\n\n[![Pane tabs drawn on the top edge of the pane with cell borders](https://www.joshka.net/cell-borders/zoom-tabs.png)](https://www.joshka.net/cell-borders/zoom-tabs.png)\n\n[![The same tabs inside a box-drawing frame](https://www.joshka.net/cell-borders/zoom-tabs-box.png)](https://www.joshka.net/cell-borders/zoom-tabs-box.png)\n\n### Charts\n\nLines between cells also work for charts. btop-style braille graphs fill every cell with dots, so\nthere's nowhere to put a gridline or an average line without giving up a row. With cell borders\nthey sit on the cell edges between the dots. Here's a monitor in that style, built with Ratatui:\n\n[![A braille CPU graph with gridlines and an average line drawn on the cell edges](https://www.joshka.net/cell-borders/chart.png)](https://www.joshka.net/cell-borders/chart.png)\n\nAnd the fallback, which has to drop the gridlines:\n\n[![The same braille graph without gridlines](https://www.joshka.net/cell-borders/chart-box.png)](https://www.joshka.net/cell-borders/chart-box.png)\n\n### In motion\n\nHere's the tiling panes demo moving panes around, opening menus and the about dialog:\n\n[![An animation of panes being dragged, split and retiled, with a menu and dialog](https://www.joshka.net/cell-borders/tour.webp)](https://www.joshka.net/cell-borders/tour.webp)\n\nPartway through, it turns on a checkerboard of the cells, which shows how everything lines up\nwith the grid. Toggle it here:\n\nShow the cell grid\n[![Two panes drawn with cell borders](https://www.joshka.net/cell-borders/grid-off.png)](https://www.joshka.net/cell-borders/grid-off.png)\n[![The same panes with alternate cells shaded, showing the borders on cell edges](https://www.joshka.net/cell-borders/grid-on.png)](https://www.joshka.net/cell-borders/grid-on.png)\n\n## What box characters can't do\n\nThe root of it is that box-drawing characters are text. Each line is a glyph that takes up a whole\ncell, and pretty much everything annoying about them falls out of that.\n\nSpace is the obvious one. On my 16\" laptop with a font I can actually read, the terminal is\nsomething like 200x50 (your prefs will move that around a bit). Columns are mostly fine at that\nsize. Rows aren't. A layout with a couple of levels of nested panels can easily spend 6 or 8 of\nthose 50 rows on nothing but lines. That's a lot of screen to give up for decoration.\n\nYou also can't put a line between two cells that both have something in them. So there's no way to\nunderline a text field right under its text, or to outline a button, without adding padding around\nit. Rounded corners sort of work, except the corner glyph has one background color, and when the\npanel's background is different from what's around it you get a little square of the wrong color\nin each corner. And the line itself is whatever the font decides it is, weight and position\nincluded.\n\nThen there's copy and paste. Select some text inside a box and you get the box too. Everyone who's\npasted from a TUI into Slack knows the little `│` cleanup dance. Sometimes you do want the box\n(pasting a table into a chat, say), but mostly it's junk. Cell borders aren't text, so they never\nget copied, which cuts both ways.\n\n## How it works\n\nA cell border is a cell attribute, like a background color. Each cell can carry up to twelve line\nsegments: the two halves of each of its four edges, and four arms from its center. Each segment\nhas its own color, width, placement and style, and the terminal draws them over the cell grid.\nBorders are stored in the cells, so they scroll, erase, insert and reflow with the text. What\nhappens on erase or scroll already has an answer, the same one as for colors.\n\nThe edges are split into halves so borders line up with quadrant block characters (`▖▗▘▝` and\nfriends). That makes it easy to draw a shape that's a half cell in from the grid and still put a\nneat border around it. Yes, that still uses a character for the fill, and there might be a better\nway to do that part. One problem at a time.\n\nThe same idea could stretch to sextants and octants, or to quarter and eighth widths, if designs\nneed them.\n\n### Styles and joints\n\n[![The gallery script showing solid, double, dashed and dotted lines, rounded corners, forks and junctions](https://www.joshka.net/cell-borders/styles.png)](https://www.joshka.net/cell-borders/styles.png)\n\n[![Rounded panels with and without an outside fill color. The first has square patches of background at its corners](https://www.joshka.net/cell-borders/zoom-outside.png)](https://www.joshka.net/cell-borders/zoom-outside.png)\n\nLines can be solid, double, dashed or dotted. Each corner and center of a cell can be square or\nrounded, with a configurable radius and anti-aliased arcs. A rounded corner can name an outside\ncolor, so the area outside the arc is painted correctly when the panel's background differs from\nwhat's behind it.\n\nWhen two neighboring cells both put a line on their shared edge, they merge into one line. The\nstroke with the higher `priority` wins, then the wider one, then the one to the right or below.\nThat way a focused pane can raise its priority and keep its whole outline, whatever order its\nneighbors were drawn in. My first try was \"right/bottom always wins\", which lasted until the\nfocused pane lost half its outline to its neighbor.\n\n## The wire format\n\nEverything is one DCS string with a namespace:\n\n```\nESC P 1 + b cell-border ; OP ; FIELDS... ESC \\\n```\n\nThe common path is a pen, held in the cursor like the current background color. Set it, print\nsome text, and the printed cells get the borders:\n\n```\nESC P 1 + b cell-border;pen;48;32;7aa2f7;0;0 ESC \\     bottom edge, blue: an underline\nhello\nESC [ 0 m                                              SGR 0 clears the pen\n```\n\nThere are also rectangle commands that set or clear borders on existing cells without touching\nthe pen, and a capability query. An app sends the query followed by DA1. If the DA1 reply arrives\nwithout a `cell-border` reply first, the terminal doesn't support it, so the app falls back to box\ncharacters and reserves the space they need. Terminals that don't understand the DCS ignore it,\nthe same as any unknown DCS.\n\nThe minimum a terminal needs is the pen, the rectangle commands and solid strokes. I've tried to\nkeep that first cut small, because there's always one more \"... and this\" to add, and that's a\nslippery slope.\n\nLine styles, rounded joints, priority and outside colors are extension fields listed in the\ncapability reply, and unknown fields are ignored, so they can be added later. I'd rather the\nearly decisions be two way doors where possible.\n\nThe spec calls itself version 1 (it's the `1` in `DCS 1 + b`). That's v1 in the old sense, before\nwe all got bogged down in semver. It doesn't mean done or stable, it means it's the first one I was willing to write\ndown. Read it as v0.1, or a draft, or whatever you prefer.\n\n## Prior art\n\nParts of this have been done before:\n\n- **DEC ruled lines** in DECterm (extension 43 in the DA1 reply) draw lines around rectangles.\n  They scroll with the text, but they're a separate layer: clearing the screen leaves them behind,\n  and they're always one pixel wide in the normal text color.\n- **SGR 51 to 65**: framed, encircled, overline and the ideogram side lines. Some terminals draw\n  borders with them, but they're on/off attributes with no color, width or joins, and there's no\n  attribute for the bottom edge.\n- The **Win32 console** has per-cell grid flags for the top, left and right edges. **PDCurses**\n  and **X/Open curses** (`WA_TOP`, `WA_LEFT` and friends) have similar attributes. These are the\n  closest to this protocol, but they have no bottom edge (Win32), color, width or halves.\n- **IBM 3270** terminals can outline whole input fields.\n\nWhat none of these give you is a line with its own color and width on each edge. The\n[rationale document](https://github.com/joshka/ghostty/blob/joshka/cell-borders/specs/cell-border-rationale.md) covers the prior art in more detail and explains each choice in\nthe protocol.\n\nMy own first prototype was in Rio ([raphamorim/rio#1947](https://github.com/raphamorim/rio/pull/1947)), with an earlier\nversion of the spec that used APC instead of DCS. Feedback pointed out that APC isn't safe to\nreuse: Kermit 95 has run APC payloads as Kermit commands since the 90s. DCS is where structured\nterminal commands already live, and terminals ignore DCS strings they don't recognize, so I\nswitched to that.\n\n## The awkward (edge) cases\n\nWhen I first showed this around, most of the questions were about these. The spec goes into all\nof them properly, but here's roughly where I landed.\n\nMultiplexers were the first thing people asked about. tmux and friends redraw panes from their own\nidea of the cell grid, so passing these sequences through would just put borders in the wrong\nplace. A multiplexer that doesn't know about the protocol should drop them and answer DA1 itself,\nand then apps running inside it fall back to box characters like they would anywhere else. One\nthat does know about it can store borders like any other attribute and redraw them.\n\nConflicting lines on a shared edge are settled when the terminal renders, using the priority rule\nabove, so it doesn't matter what order the app wrote the cells in.\n\nErase, insert and delete all work the way they do for background colors. Erased cells pick up the\ncurrent pen, and lines that get inserted or deleted take their borders along. Scrollback, the\nalternate screen and reflow mostly come for free, because the border lives in the cell.\n\nOn cost: the Ghostty change is about 1,650 lines, and a fair chunk of that is tests. Each cell gets\na 16-bit border ID, which fits in padding that was already there, so cells don't get any bigger\nand a screen with no borders costs nothing extra. The IDs point into a table of distinct border\nsets (about 100 bytes each) that's shared by the whole terminal. A typical TUI only uses a\nhandful of distinct sets, but the table is never freed, so in the worst case (all 65,535 IDs in\nuse) it's somewhere around 10-15 MB.\n\nRendering only does extra work for cells that have borders. Each one looks at its four neighbors to\nresolve shared edges, so changing a row also rebuilds the rows either side of it. Straight lines\nare a few solid quads per cell. Rounded corners cost more, because the anti-aliased arc is drawn as\nrows of small quads, roughly one per edge pixel. I haven't benchmarked any of this properly yet,\nand it's the part I'd most like another set of eyes on.\n\n## Try it\n\nThe [spec](https://github.com/joshka/ghostty/blob/joshka/cell-borders/specs/cell-border-protocol.md) and [rationale](https://github.com/joshka/ghostty/blob/joshka/cell-borders/specs/cell-border-rationale.md) are on my Ghostty fork. The [Ghostty\nbranch](https://github.com/joshka/ghostty/tree/joshka/cell-borders) implements all of version 1. I've only built and run it on macOS so far, so the\nGTK and OpenGL builds are untested. To build and run it (you'll need Zig 0.17 and Xcode):\n\n```\ngit clone -b joshka/cell-borders https://github.com/joshka/ghostty.git\ncd ghostty\nzig build -Doptimize=ReleaseFast -Dxcframework-target=native\nopen zig-out/Ghostty.app\n```\n\nInside that Ghostty, the gallery script on the same branch draws the style gallery above. It\ndetects support first, so it's also a quick check for another terminal's implementation:\n\n```\npython3 scripts/cell-borders.py            # the default view\npython3 scripts/cell-borders.py --styles   # line styles, joints and outside fill\n```\n\nOnce it's running you can flip between views with keys: `p` placement, `c` colors, `h` blocks, `j`\njunctions, `e` halves, `s` styles and `l` live. `w` cycles the stroke width, `b` turns borders off\nso you can compare, and `q` quits. Each view also has a matching flag (`--placement`, `--styles`\nand so on) if you want to start on it.\n\nThe tiling panes demo is on the [Ratatui branch](https://github.com/joshka/ratatui/tree/joshka/cell-borders). It falls back to box-drawing\ncharacters when the terminal doesn't support cell borders, which is how I made the comparison\nshots above:\n\n```\ngit clone -b joshka/cell-borders https://github.com/joshka/ratatui.git\ncd ratatui\ncargo run -p tiling-panes\n```\n\nDrag panes around with the mouse to retile them. `n` and `v` split, `x` closes, and right click\nopens a pane menu. Press `b` to switch between cell borders and box drawing, or `g` to shade\nalternate cells and see where the edges are.\n\nThe btop-style monitor from the chart screenshots is in the same branch. Given how much of it an AI\nwrote, I did briefly consider calling it bslop:\n\n[![The full btop-style monitor drawn with cell borders. The hostname is blurred](https://www.joshka.net/cell-borders/bslop.png)](https://www.joshka.net/cell-borders/bslop.png)\n\nTo run it:\n\n```\ncargo run -p cell-border-top\n```\n\nIt's a real system monitor (it reads your actual CPU, memory, network and processes), so it's a\nbetter test of how this looks on a busy screen than the panes demo. `1` to `4` show and hide the\nboxes, `b` and `g` work the same as in the panes demo, and `h` or `?` lists the rest of the keys.\nIt needs a newer Rust (1.95) than the rest of Ratatui because of the `sysinfo` dependency.\n\n## What I'd like to hear\n\nI'm not attached to this being the exact solution, but I think it's a problem worth solving, and\nI'd like it to be more than one terminal's feature (and more than one weekend's worth of yak\nshaving). If you work on a terminal, would you implement this, and which parts look expensive? If you work on a TUI library or app, which of your widgets\nwould use it, and what would they need that isn't here? Comments are welcome on the\n[Ghostty discussion](https://github.com/ghostty-org/ghostty/discussions/14324).\n","body_html":"<h1 id=\"terminal-borders-that-don-t-cost-a-cell\"><a href=\"https://www.joshka.net/cell-borders/\" rel=\"nofollow ugc noopener\">Terminal borders that don&#39;t cost a cell</a></h1>\n<p>2026-11-13</p>\n<p> :: tags: \n<a href=\"https://www.joshka.net/tags/ghostty/\" rel=\"nofollow ugc noopener\">#Ghostty</a> \n<a href=\"https://www.joshka.net/tags/ratatui/\" rel=\"nofollow ugc noopener\">#Ratatui</a> \n<a href=\"https://www.joshka.net/tags/tui/\" rel=\"nofollow ugc noopener\">#TUI</a> \n<a href=\"https://www.joshka.net/tags/terminals/\" rel=\"nofollow ugc noopener\">#Terminals</a></p>\n<p>*This post (and the code behind it) was written with a lot of help from AI. I&#39;m not going to\napologize for that. If that bothers you, feel free to close the tab.*</p>\n<p>I maintain <a href=\"https://ratatui.rs\" rel=\"nofollow ugc noopener\">Ratatui</a>, so I see a lot of the TUIs people build. Many of them end up looking fairly\nsame-ish: plain boxes on a boring background, missing a bunch of the things that good design in\nother mediums brings us.</p>\n<p>Borders are part of the problem. They have to take up space, so they become part of the panels\npeople want to build. One option is to drop them and just use color, but borders are really nice\nfor delineating and surrounding things. There are lots of ways to sort of get borders in a\nterminal, but none that are 100% good. I&#39;ve drawn enough <code>┌──┐</code> by hand to have opinions about\nthis.</p>\n<p>The usual way is the Unicode Box Drawing block, which has 128 characters for lines, corners and\njoins. Somehow that&#39;s still not enough:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/box-drawing-block.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/box-drawing-block.png\" alt=\"The Unicode Box Drawing block, U+2500 to U+257F, rendered in Ghostty\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>So I&#39;ve been working on a terminal protocol that draws thin lines on the edges of cells instead.\nI&#39;ve got it working as <a href=\"https://github.com/joshka/ghostty/tree/joshka/cell-borders\" rel=\"nofollow ugc noopener\">a patch to Ghostty</a> (and <a href=\"https://github.com/raphamorim/rio/pull/1947\" rel=\"nofollow ugc noopener\">an earlier version in\nRio</a> before that), and\nI&#39;ve built demo apps for it with Ratatui. I&#39;d like feedback from\nterminal and TUI authors.</p>\n<p><a href=\"https://www.joshka.net/cell-borders/panes.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/panes.png\" alt=\"A tiling window manager demo built with Ratatui, using cell borders for panes, tabs, form fields and buttons\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>Every line in that screenshot is a cell border. None of them use up a row or column. The tab\nlabels sit on the top edge of each pane, the text fields are underlined right under the text, and\nthe buttons are one row tall and rounded.</p>\n<p>Here&#39;s the same app in a terminal without cell borders, falling back to box-drawing characters:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/panes-box.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/panes-box.png\" alt=\"The same demo drawn with box-drawing characters\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>Each pane loses a row and a column on every side, so the log pane shows two fewer lines and the\nnotes wrap differently. The tab labels move inside the frame. The text fields use the underline\nattribute instead, and the checkbox and buttons turn into brackets.</p>\n<h2 id=\"what-i-d-use-it-for\">What I&#39;d use it for</h2>\n<ul><li>Borders, obviously. Panes and panels that don&#39;t eat a row and column on every side.</li><li>Menus and popups that sit on top of other content and still look like they&#39;re on top.</li><li>Panel style apps, where the layout is a set of regions that each want an edge.</li><li>Widgets like text fields, buttons and checkboxes, which want a line right up against their text.</li><li><p>Making things look neater in general. A border on the outer edge of a panel&#39;s background looks</p><p>a lot cleaner, and text can run right up to it.</p></li></ul>\n<h3 id=\"up-close\">Up close</h3>\n<p>The settings form, with cell borders and then with the box-drawing fallback:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/zoom-form.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/zoom-form.png\" alt=\"A form with underlined text fields, a checkbox and rounded buttons drawn with cell borders\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p><a href=\"https://www.joshka.net/cell-borders/zoom-form-box.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/zoom-form-box.png\" alt=\"The same form with the underline attribute and bracketed buttons\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>The tabs are the same story. With cell borders they sit on the pane&#39;s top edge. With box\ncharacters they need their own row inside the frame:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/zoom-tabs.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/zoom-tabs.png\" alt=\"Pane tabs drawn on the top edge of the pane with cell borders\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p><a href=\"https://www.joshka.net/cell-borders/zoom-tabs-box.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/zoom-tabs-box.png\" alt=\"The same tabs inside a box-drawing frame\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<h3 id=\"charts\">Charts</h3>\n<p>Lines between cells also work for charts. btop-style braille graphs fill every cell with dots, so\nthere&#39;s nowhere to put a gridline or an average line without giving up a row. With cell borders\nthey sit on the cell edges between the dots. Here&#39;s a monitor in that style, built with Ratatui:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/chart.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/chart.png\" alt=\"A braille CPU graph with gridlines and an average line drawn on the cell edges\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>And the fallback, which has to drop the gridlines:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/chart-box.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/chart-box.png\" alt=\"The same braille graph without gridlines\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<h3 id=\"in-motion\">In motion</h3>\n<p>Here&#39;s the tiling panes demo moving panes around, opening menus and the about dialog:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/tour.webp\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/tour.webp\" alt=\"An animation of panes being dragged, split and retiled, with a menu and dialog\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>Partway through, it turns on a checkerboard of the cells, which shows how everything lines up\nwith the grid. Toggle it here:</p>\n<p>Show the cell grid\n<a href=\"https://www.joshka.net/cell-borders/grid-off.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/grid-off.png\" alt=\"Two panes drawn with cell borders\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a>\n<a href=\"https://www.joshka.net/cell-borders/grid-on.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/grid-on.png\" alt=\"The same panes with alternate cells shaded, showing the borders on cell edges\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<h2 id=\"what-box-characters-can-t-do\">What box characters can&#39;t do</h2>\n<p>The root of it is that box-drawing characters are text. Each line is a glyph that takes up a whole\ncell, and pretty much everything annoying about them falls out of that.</p>\n<p>Space is the obvious one. On my 16&quot; laptop with a font I can actually read, the terminal is\nsomething like 200x50 (your prefs will move that around a bit). Columns are mostly fine at that\nsize. Rows aren&#39;t. A layout with a couple of levels of nested panels can easily spend 6 or 8 of\nthose 50 rows on nothing but lines. That&#39;s a lot of screen to give up for decoration.</p>\n<p>You also can&#39;t put a line between two cells that both have something in them. So there&#39;s no way to\nunderline a text field right under its text, or to outline a button, without adding padding around\nit. Rounded corners sort of work, except the corner glyph has one background color, and when the\npanel&#39;s background is different from what&#39;s around it you get a little square of the wrong color\nin each corner. And the line itself is whatever the font decides it is, weight and position\nincluded.</p>\n<p>Then there&#39;s copy and paste. Select some text inside a box and you get the box too. Everyone who&#39;s\npasted from a TUI into Slack knows the little <code>│</code> cleanup dance. Sometimes you do want the box\n(pasting a table into a chat, say), but mostly it&#39;s junk. Cell borders aren&#39;t text, so they never\nget copied, which cuts both ways.</p>\n<h2 id=\"how-it-works\">How it works</h2>\n<p>A cell border is a cell attribute, like a background color. Each cell can carry up to twelve line\nsegments: the two halves of each of its four edges, and four arms from its center. Each segment\nhas its own color, width, placement and style, and the terminal draws them over the cell grid.\nBorders are stored in the cells, so they scroll, erase, insert and reflow with the text. What\nhappens on erase or scroll already has an answer, the same one as for colors.</p>\n<p>The edges are split into halves so borders line up with quadrant block characters (<code>▖▗▘▝</code> and\nfriends). That makes it easy to draw a shape that&#39;s a half cell in from the grid and still put a\nneat border around it. Yes, that still uses a character for the fill, and there might be a better\nway to do that part. One problem at a time.</p>\n<p>The same idea could stretch to sextants and octants, or to quarter and eighth widths, if designs\nneed them.</p>\n<h3 id=\"styles-and-joints\">Styles and joints</h3>\n<p><a href=\"https://www.joshka.net/cell-borders/styles.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/styles.png\" alt=\"The gallery script showing solid, double, dashed and dotted lines, rounded corners, forks and junctions\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p><a href=\"https://www.joshka.net/cell-borders/zoom-outside.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/zoom-outside.png\" alt=\"Rounded panels with and without an outside fill color. The first has square patches of background at its corners\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>Lines can be solid, double, dashed or dotted. Each corner and center of a cell can be square or\nrounded, with a configurable radius and anti-aliased arcs. A rounded corner can name an outside\ncolor, so the area outside the arc is painted correctly when the panel&#39;s background differs from\nwhat&#39;s behind it.</p>\n<p>When two neighboring cells both put a line on their shared edge, they merge into one line. The\nstroke with the higher <code>priority</code> wins, then the wider one, then the one to the right or below.\nThat way a focused pane can raise its priority and keep its whole outline, whatever order its\nneighbors were drawn in. My first try was &quot;right/bottom always wins&quot;, which lasted until the\nfocused pane lost half its outline to its neighbor.</p>\n<h2 id=\"the-wire-format\">The wire format</h2>\n<p>Everything is one DCS string with a namespace:</p>\n<pre><code>ESC P 1 + b cell-border ; OP ; FIELDS... ESC \\</code></pre>\n<p>The common path is a pen, held in the cursor like the current background color. Set it, print\nsome text, and the printed cells get the borders:</p>\n<pre><code>ESC P 1 + b cell-border;pen;48;32;7aa2f7;0;0 ESC \\     bottom edge, blue: an underline\nhello\nESC [ 0 m                                              SGR 0 clears the pen</code></pre>\n<p>There are also rectangle commands that set or clear borders on existing cells without touching\nthe pen, and a capability query. An app sends the query followed by DA1. If the DA1 reply arrives\nwithout a <code>cell-border</code> reply first, the terminal doesn&#39;t support it, so the app falls back to box\ncharacters and reserves the space they need. Terminals that don&#39;t understand the DCS ignore it,\nthe same as any unknown DCS.</p>\n<p>The minimum a terminal needs is the pen, the rectangle commands and solid strokes. I&#39;ve tried to\nkeep that first cut small, because there&#39;s always one more &quot;... and this&quot; to add, and that&#39;s a\nslippery slope.</p>\n<p>Line styles, rounded joints, priority and outside colors are extension fields listed in the\ncapability reply, and unknown fields are ignored, so they can be added later. I&#39;d rather the\nearly decisions be two way doors where possible.</p>\n<p>The spec calls itself version 1 (it&#39;s the <code>1</code> in <code>DCS 1 + b</code>). That&#39;s v1 in the old sense, before\nwe all got bogged down in semver. It doesn&#39;t mean done or stable, it means it&#39;s the first one I was willing to write\ndown. Read it as v0.1, or a draft, or whatever you prefer.</p>\n<h2 id=\"prior-art\">Prior art</h2>\n<p>Parts of this have been done before:</p>\n<ul><li><p><strong>DEC ruled lines</strong> in DECterm (extension 43 in the DA1 reply) draw lines around rectangles.</p><p>They scroll with the text, but they&#39;re a separate layer: clearing the screen leaves them behind,\nand they&#39;re always one pixel wide in the normal text color.</p></li><li><p><strong>SGR 51 to 65</strong>: framed, encircled, overline and the ideogram side lines. Some terminals draw</p><p>borders with them, but they&#39;re on/off attributes with no color, width or joins, and there&#39;s no\nattribute for the bottom edge.</p></li><li><p>The <strong>Win32 console</strong> has per-cell grid flags for the top, left and right edges. <strong>PDCurses</strong></p><p>and <strong>X/Open curses</strong> (<code>WA_TOP</code>, <code>WA_LEFT</code> and friends) have similar attributes. These are the\nclosest to this protocol, but they have no bottom edge (Win32), color, width or halves.</p></li><li><strong>IBM 3270</strong> terminals can outline whole input fields.</li></ul>\n<p>What none of these give you is a line with its own color and width on each edge. The\n<a href=\"https://github.com/joshka/ghostty/blob/joshka/cell-borders/specs/cell-border-rationale.md\" rel=\"nofollow ugc noopener\">rationale document</a> covers the prior art in more detail and explains each choice in\nthe protocol.</p>\n<p>My own first prototype was in Rio (<a href=\"https://github.com/raphamorim/rio/pull/1947\" rel=\"nofollow ugc noopener\">raphamorim/rio#1947</a>), with an earlier\nversion of the spec that used APC instead of DCS. Feedback pointed out that APC isn&#39;t safe to\nreuse: Kermit 95 has run APC payloads as Kermit commands since the 90s. DCS is where structured\nterminal commands already live, and terminals ignore DCS strings they don&#39;t recognize, so I\nswitched to that.</p>\n<h2 id=\"the-awkward-edge-cases\">The awkward (edge) cases</h2>\n<p>When I first showed this around, most of the questions were about these. The spec goes into all\nof them properly, but here&#39;s roughly where I landed.</p>\n<p>Multiplexers were the first thing people asked about. tmux and friends redraw panes from their own\nidea of the cell grid, so passing these sequences through would just put borders in the wrong\nplace. A multiplexer that doesn&#39;t know about the protocol should drop them and answer DA1 itself,\nand then apps running inside it fall back to box characters like they would anywhere else. One\nthat does know about it can store borders like any other attribute and redraw them.</p>\n<p>Conflicting lines on a shared edge are settled when the terminal renders, using the priority rule\nabove, so it doesn&#39;t matter what order the app wrote the cells in.</p>\n<p>Erase, insert and delete all work the way they do for background colors. Erased cells pick up the\ncurrent pen, and lines that get inserted or deleted take their borders along. Scrollback, the\nalternate screen and reflow mostly come for free, because the border lives in the cell.</p>\n<p>On cost: the Ghostty change is about 1,650 lines, and a fair chunk of that is tests. Each cell gets\na 16-bit border ID, which fits in padding that was already there, so cells don&#39;t get any bigger\nand a screen with no borders costs nothing extra. The IDs point into a table of distinct border\nsets (about 100 bytes each) that&#39;s shared by the whole terminal. A typical TUI only uses a\nhandful of distinct sets, but the table is never freed, so in the worst case (all 65,535 IDs in\nuse) it&#39;s somewhere around 10-15 MB.</p>\n<p>Rendering only does extra work for cells that have borders. Each one looks at its four neighbors to\nresolve shared edges, so changing a row also rebuilds the rows either side of it. Straight lines\nare a few solid quads per cell. Rounded corners cost more, because the anti-aliased arc is drawn as\nrows of small quads, roughly one per edge pixel. I haven&#39;t benchmarked any of this properly yet,\nand it&#39;s the part I&#39;d most like another set of eyes on.</p>\n<h2 id=\"try-it\">Try it</h2>\n<p>The <a href=\"https://github.com/joshka/ghostty/blob/joshka/cell-borders/specs/cell-border-protocol.md\" rel=\"nofollow ugc noopener\">spec</a> and <a href=\"https://github.com/joshka/ghostty/blob/joshka/cell-borders/specs/cell-border-rationale.md\" rel=\"nofollow ugc noopener\">rationale</a> are on my Ghostty fork. The <a href=\"https://github.com/joshka/ghostty/tree/joshka/cell-borders\" rel=\"nofollow ugc noopener\">Ghostty\nbranch</a> implements all of version 1. I&#39;ve only built and run it on macOS so far, so the\nGTK and OpenGL builds are untested. To build and run it (you&#39;ll need Zig 0.17 and Xcode):</p>\n<pre><code>git clone -b joshka/cell-borders https://github.com/joshka/ghostty.git\ncd ghostty\nzig build -Doptimize=ReleaseFast -Dxcframework-target=native\nopen zig-out/Ghostty.app</code></pre>\n<p>Inside that Ghostty, the gallery script on the same branch draws the style gallery above. It\ndetects support first, so it&#39;s also a quick check for another terminal&#39;s implementation:</p>\n<pre><code>python3 scripts/cell-borders.py            # the default view\npython3 scripts/cell-borders.py --styles   # line styles, joints and outside fill</code></pre>\n<p>Once it&#39;s running you can flip between views with keys: <code>p</code> placement, <code>c</code> colors, <code>h</code> blocks, <code>j</code>\njunctions, <code>e</code> halves, <code>s</code> styles and <code>l</code> live. <code>w</code> cycles the stroke width, <code>b</code> turns borders off\nso you can compare, and <code>q</code> quits. Each view also has a matching flag (<code>--placement</code>, <code>--styles</code>\nand so on) if you want to start on it.</p>\n<p>The tiling panes demo is on the <a href=\"https://github.com/joshka/ratatui/tree/joshka/cell-borders\" rel=\"nofollow ugc noopener\">Ratatui branch</a>. It falls back to box-drawing\ncharacters when the terminal doesn&#39;t support cell borders, which is how I made the comparison\nshots above:</p>\n<pre><code>git clone -b joshka/cell-borders https://github.com/joshka/ratatui.git\ncd ratatui\ncargo run -p tiling-panes</code></pre>\n<p>Drag panes around with the mouse to retile them. <code>n</code> and <code>v</code> split, <code>x</code> closes, and right click\nopens a pane menu. Press <code>b</code> to switch between cell borders and box drawing, or <code>g</code> to shade\nalternate cells and see where the edges are.</p>\n<p>The btop-style monitor from the chart screenshots is in the same branch. Given how much of it an AI\nwrote, I did briefly consider calling it bslop:</p>\n<p><a href=\"https://www.joshka.net/cell-borders/bslop.png\" rel=\"nofollow ugc noopener\"><img src=\"https://www.joshka.net/cell-borders/bslop.png\" alt=\"The full btop-style monitor drawn with cell borders. The hostname is blurred\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></a></p>\n<p>To run it:</p>\n<pre><code>cargo run -p cell-border-top</code></pre>\n<p>It&#39;s a real system monitor (it reads your actual CPU, memory, network and processes), so it&#39;s a\nbetter test of how this looks on a busy screen than the panes demo. <code>1</code> to <code>4</code> show and hide the\nboxes, <code>b</code> and <code>g</code> work the same as in the panes demo, and <code>h</code> or <code>?</code> lists the rest of the keys.\nIt needs a newer Rust (1.95) than the rest of Ratatui because of the <code>sysinfo</code> dependency.</p>\n<h2 id=\"what-i-d-like-to-hear\">What I&#39;d like to hear</h2>\n<p>I&#39;m not attached to this being the exact solution, but I think it&#39;s a problem worth solving, and\nI&#39;d like it to be more than one terminal&#39;s feature (and more than one weekend&#39;s worth of yak\nshaving). If you work on a terminal, would you implement this, and which parts look expensive? If you work on a TUI library or app, which of your widgets\nwould use it, and what would they need that isn&#39;t here? Comments are welcome on the\n<a href=\"https://github.com/ghostty-org/ghostty/discussions/14324\" rel=\"nofollow ugc noopener\">Ghostty discussion</a>.</p>","headings":[{"level":1,"text":"Terminal borders that don't cost a cell","id":"terminal-borders-that-don-t-cost-a-cell"},{"level":2,"text":"What I'd use it for","id":"what-i-d-use-it-for"},{"level":3,"text":"Up close","id":"up-close"},{"level":3,"text":"Charts","id":"charts"},{"level":3,"text":"In motion","id":"in-motion"},{"level":2,"text":"What box characters can't do","id":"what-box-characters-can-t-do"},{"level":2,"text":"How it works","id":"how-it-works"},{"level":3,"text":"Styles and joints","id":"styles-and-joints"},{"level":2,"text":"The wire format","id":"the-wire-format"},{"level":2,"text":"Prior art","id":"prior-art"},{"level":2,"text":"The awkward (edge) cases","id":"the-awkward-edge-cases"},{"level":2,"text":"Try it","id":"try-it"},{"level":2,"text":"What I'd like to hear","id":"what-i-d-like-to-hear"}]}}