This repository was archived by the owner on Nov 12, 2026. It is now read-only.
Repository navigation
feat(dioxus-tui): paint the leaf-dioxus editor into terminal cells - #20
Merged
Merged
Conversation
A prototype answering whether the Dioxus editor could replace leaf-tui. Dioxus 0.8 has no terminal renderer: dioxus-tui left the Dioxus repo in March 2024 (7cc326488) and Blitz did not keep it. So this keeps Blitz's DOM, styles and layout as the Mac app uses them and replaces only the painter: apps/leaf-dioxus-tui walks the laid-out tree and writes cells. The editor runs unchanged on a windowless DioxusDocument with a stub winit window, crossterm keys handed to Editor::key, clicks as Blitz pointer events. A monospace face at one cell per advance makes the editor's own parley layout count in cells. No change to leaf-dioxus or unit. docs/proposals/the-leaf-dioxus-editor-in-a-terminal.md has the routes, what the prototype does and does not do against leaf-tui, and the decisions left to make.
…hics protocol The painter records each img's box in cells and the rows of it in view; ratatui-image paints the decoded picture over them (kitty, iTerm2, sixel, or half-blocks), cropped when it is part-way off the screen and trimmed under the status line. Files load through leaf-raster as in leaf-tui; formulas and diagrams arrive as SVG data URLs and are rasterised. The terminal output moves to ratatui, which diffs the cells.
…n a grid Type::uniform, off by default, sets headings and super- and subscripts at the body size in every view, as the source view already does: the editor's parley layout and the stylesheet agree, a heading bold but no larger. A terminal host needs it, where text larger than a cell cannot be drawn and a click must land on the character drawn under it. Type gains a field, so a Type written out field by field needs it added (the Mac app's Settings::ty does, with `uniform: false`).
…tui's flags The page is under unit's root in its new cell density, as the Mac app's is under its root, and every key reaches unit first. From one command table: the command menu (⌃P or F10), each item showing its keys, and the context menu on a right-click. The Link and Save As prompts are unit dialogs; quitting with unsaved changes and a save over a file changed on disk ask through unit's action sheet, answered from the keyboard. A clean document reloads an outside write once the file stands still, as leaf-tui's does. -r reads only and -w N sets the column, and the terminal is asked whether it is light or dark. The painter draws borders over a box's children, with corners, and a horizontal side only in a row it owns that nothing is written in; a thin filled box is a rule. Clicks are shifted as the text's start is rounded, and every run is at the body size (Type::uniform), so a click lands on the character drawn under it. The loop repaints after a timer changes the page, and follows the terminal's size every turn.
… and the file features
A graphics-protocol picture is painted after the cells, over its whole box, so a context menu or the command menu opened over a picture was hidden under it. Only a box across the picture's full width (the status line) trimmed it. Now any opaque box drawn after a picture covers it there: the picture keeps the largest rectangle the box leaves uncovered, above, below or beside it, and is cropped to it on both axes.
The painter, the terminal, the pictures' protocol and the winit window stub move to blitz-tui, a package on diaryx-org/blitz's tui branch, which runs any Blitz document. What stays is leaf's: the editor and unit's chrome, the command table, the file rules, ⌃ as ⌘ for the editor's shortcuts, the caret classes, the click shift by the editor's padding, and leaf-raster as the picture decoder. Every Blitz crate now comes from the tui branch. Behavioural-change: a table's bottom border is drawn; a horizontal border takes the row boundary nearest it.
…tui has merged diaryx-org/blitz#12 merged the tui branch into leaf, so the prototype takes every Blitz crate from leaf, as apps/leaf-dioxus does. The proposal marks decision 6 as settled, apart from offering blitz-tui upstream.
… whole cells Type::uniform becomes Type::grid, which carries the host's cell. On a grid every run is still set at the body size, and now the find bar and the status line are a row each, and a table is padded a cell either side with rules a cell wide or a row high. Its columns are whole cells, and it is ruled under the head and the last row only, as core's picture of a table is. Two fixes on the way, in a window too. A centred or right-aligned cell narrower than 64px was laid out 64px wide, so a click in it landed left of the character drawn under it; a cell is now laid out at its column's width. And the first column's cells draw the table's left rule inside their width, which hit-testing counted outside it; they are now that rule wider. Behavioural-change: in a window, a click in a centred or right-aligned table cell narrower than 64px lands on the character under it, and a table's first column is 1px wider.
…s fit the grid The prototype hands the editor its cell as Type::grid and drops its own CSS for the find bar and the status line. A table's cell lines keep out of the line-width workaround, which moved right-aligned text off its padding. Blitz comes from the fork's tui-junctions branch, which joins borders that meet, until diaryx-org/blitz#14 merges into leaf. The proposal marks decision 2 as made.
…the joined borders have merged diaryx-org/blitz#14 merged tui-junctions into leaf, so every Blitz crate comes from leaf, as apps/leaf-dioxus takes it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A prototype answering: does Dioxus have a TUI renderer, and could the leaf-dioxus editor replace leaf-tui? Adam asked to keep going after the first round, so it now has pictures, unit's chrome and the file features.
Dioxus has no terminal renderer today.
dioxus-tui(rink/plasmo) last shipped as0.5.0-alpha.0and left the Dioxus repo in7cc326488(2024-03-15). Blitz has no TUI package.The route: keep Blitz's DOM, Stylo and taffy layout as the Mac app uses them, and replace only the painter.
apps/leaf-dioxus-tuipaints the laid-out tree into character cells, and the editor runs on it unchanged.What it does:
-r(read-only) and-w N(column width).Commits:
feat(dioxus):Type::grid, the host's cell. On a grid every run is set at the body size, so a click on a heading lands where it is drawn, and the find bar, the status line and tables are sized in whole cells: a row each for the bar and the status line, and a table ruled under its head and last row, as core's picture of a table is. Off by default. It also fixes two table faults the Mac app has too: a click in a narrow right-aligned or centred cell, and the first column's width (Behavioural-changetrailer);dioxus-tuibranch (feat(theme): a cell density, for a renderer that paints into a terminal's cells unit#10), which adds a cell density;docs/proposals/the-leaf-dioxus-editor-in-a-terminal.mdhas what is left against leaf-tui and the decisions to make.leaf-tui is untouched.
Checks:
ship cifmt, clippy and test in the root workspace (1,326 pass);ship ci dioxusfor the widget and the Mac app (154 pass); and the prototype's own fmt, clippy and 14 tests. No CI job builds the prototype.Update: the renderer has moved to the Blitz fork. It is now
blitz-tui, a package ondiaryx-org/blitz'sleafbranch (merged in diaryx-org/blitz#12), and it runs any Blitz document, including a Dioxus app. This app now holds only the parts that are leaf's. Every Blitz crate comes from the fork'sleafbranch, as the Mac app takes it. diaryx-org/blitz#14, merged, joins borders that meet (┬ ┼ ├), so a table's cells read as one grid.