mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Render Mermaid code blocks as diagrams in the TUI (#46054)
## What changed - Render completed `mermaid` fences with `codex-mermaid`, using syntax-theme colors for nodes and edges. - Keep source visible for unclosed, invalid, unsupported, or oversized diagrams, and preserve the original Mermaid for copying and raw mode. - Keep streamed diagrams mutable until the next top-level block so closing fences and terminal resizing can update their display. Preserve scrollback progress across width and render-mode changes. ## Testing Add renderer and streaming tests covering supported diagram families, nested fences, Unicode, theme colors, source fallbacks, resizing, raw-mode transitions, and original-source preservation. Verify that node connection ports retain node styling in all four flowchart directions. GitOrigin-RevId: 9a759248110e6730d629d653061ff7e2ec5dc2c0
This commit is contained in:
1 parent
c56dda711c
commit
f915e0de07
18 files changed
+682
-42
No files matched your search
@@ -168,8 +168,8 @@ pub(super) fn render(graph: &Graph, max_width: usize) -> Result<Vec<Vec<Span>>,
|
||||
canvas.set(x, y, Cell::edge(ch));
|
||||
}
|
||||
}
|
||||
canvas.set(box_cross - 1, source, Cell::edge('├'));
|
||||
canvas.set(box_cross - 1, target, Cell::edge('├'));
|
||||
canvas.set(box_cross - 1, source, Cell::node('├'));
|
||||
canvas.set(box_cross - 1, target, Cell::node('├'));
|
||||
canvas.set(box_cross, source, Cell::edge(edge.source_tip));
|
||||
canvas.set(box_cross, target, Cell::edge(edge.target_tip));
|
||||
canvas.set(
|
||||
|
||||
@@ -190,4 +190,22 @@ fn semantic_spans_distinguish_labels_from_matching_endpoint_glyphs() {
|
||||
.role,
|
||||
Role::Node
|
||||
);
|
||||
for direction in ["TD", "BT", "LR", "RL"] {
|
||||
let lines = super::render_spans(
|
||||
&format!("flowchart {direction}; A --> B"),
|
||||
/*max_width*/ 100,
|
||||
)
|
||||
.unwrap();
|
||||
let ports = lines
|
||||
.iter()
|
||||
.flatten()
|
||||
.flat_map(|span| {
|
||||
span.text
|
||||
.chars()
|
||||
.filter(|ch| matches!(ch, '├' | '┬'))
|
||||
.map(|_| span.role)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(ports, vec![Role::Node, Role::Node]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user