Repository navigation
Fix(tui): Mermaid flowcharts show every node and edge at any pane width - #39
Merged
Merged
Conversation
A left-to-right flowchart wider than the pane was cut off with no way to see the rest, and its labels kept their source quotes. Width was only part of it: the library's text layout routes no edges, so its boxes overlap, an edge back to an earlier node and every edge label are dropped, and a branch is drawn through the boxes between. zn now keeps the library's parser and draws flowcharts and state diagrams itself: a row of boxes when a left-to-right diagram fits, otherwise a column with wrapped labels. An edge to the box drawn next is an arrow between them, and any other edge is listed under its source by the name of its target. Parsing is cached by content and only the layout follows the width. The parser ends a quoted label at its first closing bracket and loses the edge after it, drops a label given after a node's first use, and skips spellings like `A -- yes --> B`. zn works around these. When a statement still cannot have been read in full, the block shows its source and says so. Sequence, class and ER diagrams still come from the library, and show their source when they do not fit. Tables and aliases in the reading view had bugs of their own. In the default style, aliased links pushed column rules out of line and a wrapped alias showed its token brackets. In the zen style, an alias's pipe split the cell, wide cells were cut off, and tables with no outer pipes did not render. `[[Note\|alias]]` now follows Note, not `Note\`.
Review of the first version found a panic and diagram content lost with no note. A label holding the runes zn used to hide quoted text ended the app, so zn now picks runes the note does not hold. IDs that start with a keyword, like title-bar, vanished with their edges. `A --o B --> C` drew a false edge label. The read-in-full check now compares the edges and the node IDs of each statement, for every statement that can name one, so a circle or cross edge, trailing words and a statement word used as an ID show the source. Quote marks open only where a label can start and no longer pair across statements, arrows inside a label stay text, and `A-->B[x]` with no spaces is read as an edge. A second label for a node and a group never closed show the source too. Two nodes with one label show their IDs, and an empty label shows its ID. In the reading view, a note's own token brackets and hard spaces are kept, a table cell's padding goes at its end, and a zen table only protects pipes inside a real wikilink.
Table padding treated a pipe inside a link's alias as a column rule, so `a|b` showed as `a |b`. A rule inside a link token is now skipped. The test helper zenTable becomes zenTableText, since another open pull request adds a helper with that name.
At the end of the file it conflicted with the tests another open pull request adds there.
A second review of the text diagrams found more that was misread. A state's :::class became a label and could lose the edge, and a %% comment holding a semicolon drew false edges from its text, because comments were cut after the line was split into statements. `A --> C(f(x))` lost its closer without a note, since any leftover closer counted as a doubled shape's; closers are now only allowed when the shape opened doubled. IDs in any script now draw. The parser's IDs are ASCII, so others are renamed while it reads them, and this also covers IDs with dots. Entities like #amp; and #35; decode, an empty diagram says it has nothing to draw, and front matter with CRLF line ends is skipped. Two long inputs are now linear: a zen table row of many links, and picking mask runes for a label holding many private-use runes. A zen table also keeps a row with no outer pipes once its separator has been seen.
A diagram with no node yet can also be marked as one zn cannot fully draw. The note that it has nothing to draw is the true one, so it is checked first.
The note that a diagram has nothing to draw is for one that really is empty. A statement the parser could not read also leaves no nodes, and that still says the source is shown.
This was referenced Nov 4, 2026
1 task
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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 Discord report (Greed) showed a Mermaid flowchart in the preview cut off at
"jj describ…". Steps D, E and F and the loop back to A could not be seen at all, so the diagram misled, and labels kept their source quotes.Why not just re-render top-down
The library's text layout routes no edges, so it loses information at any width. Left-to-right boxes overlap, an edge back to an earlier node and every edge label are dropped, and a branch draws through the boxes between (
O│e). Greed's loop back would still have been missing.What changes
Flowcharts and state diagrams. zn keeps the library's parser, with no fork, and draws them itself in
internal/tui/mermaidtext.go:└─▶ edit files in @.<br/>in labels all show.Parser gaps, worked around in zn. These belong upstream in the library's
parser/flowchart.go; nothing has been filed there.A -- yes --> B,A -. yes .-> B,A == yes ==> Band longer arrows lost the edge silently.When zn cannot be sure. A statement the parser cannot have read in full (
A --x B,A ~~~ B,A@{ ... }, a statenote) shows the block's source with a note. So does a sequence, class or ER diagram wider than the pane. Errors now wrap instead of being cut off.Tables and aliases, reproduced while checking the rest of the report:
⟦ ⟧zenzenzen[[Note|alias]]links pointed atNote\Before and after
Real TUI at 100 columns in split view. Before:
After, end of the column:
At 240 columns it stays one row, with the loop listed below:
Speed
Parsing is cached by content, and only the layout follows the width. A 500-node diagram took about 5 ms to parse and 2 ms to lay out, in one run.
Known limits
mmdcpicture code is unchanged.TestMermaidPictureStillReplacesTheTextcovers it with a fakemmdc; it was not run in a real Kitty terminal.…. That comes fromlipgloss, which truncates headers, and is left as is.[[Bookmarks|bookmarks]]shows asbookmarksin preview here, so theBookmarks|bookmarksin Greed's screenshot was not reproduced there. Tables not rendering in the default style was not reproduced either; there was no screenshot of it.Testing
go test ./...andgo vet ./...pass, and the affected tests pass with-race. Tests ininternal/tui/mermaidtext_test.gofailed before the fix.Review fixes
An independent review of the first commit found a panic and diagram content lost with no note. The second commit fixes these, with a test for each:
title-bar,click) vanished, andA --o B --> Cdrew a false edge label.A-->B[x]with no spaces is read as an edge.⟦,⟧and hard spaces are kept. A table cell's padding goes at its end. A zen table only protects pipes inside a real wikilink.Second review
A second review found more that was misread, fixed in later commits with tests:
:::classbecame a label and could lose the edge.%%comment holding a semicolon drew false edges.A --> C(f(x))lost its closer without a note, so a leftover closer now shows the source.#amp;decode. An empty diagram says it has nothing to draw. CRLF front matter is skipped.Not fixed
state "Big one" as B {...}thenA --> Bdraws a boxB, and only the group list saysBig one.U+10FFF0range reads as one of the preview's own stand-ins.[[Note\|]]and backlinks of[[Note\|alias]]depend on the escaped-pipe PRs in this release.