Skip to content

Commit 6fa625e

Browse files
authored
Rollup merge of #76500 - richkadel:mir-graphviz-dark, r=tmandry
Add -Zgraphviz_dark_mode and monospace font fix Many developers use a dark theme with editors and IDEs, but this typically doesn't extend to graphviz output. When I bring up a MIR graphviz document, the white background is strikingly bright. This new option changes the colors used for graphviz output to work better in dark-themed UIs. <img width="1305" alt="Screen Shot 2020-09-09 at 3 00 31 PM" src="https://user-images.githubusercontent.com/3827298/92659478-4b9bff00-f2ad-11ea-8894-b40d3a873cb9.png"> Also fixed the monospace font for common graphviz renders (e.g., VS Code extensions), as described in rust-lang/rust#76500 (comment) **Before:** <img width="943" alt="Screen Shot 2020-09-09 at 2 48 44 PM" src="https://user-images.githubusercontent.com/3827298/92658939-47231680-f2ac-11ea-97ac-96727e4dd622.png"> **Now with fix:** <img width="943" alt="Screen Shot 2020-09-09 at 2 49 02 PM" src="https://user-images.githubusercontent.com/3827298/92658959-51451500-f2ac-11ea-9aae-de982d466d6a.png">
2 parents 11d4c09 + 61f6307 commit 6fa625e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ pub enum RenderOption {
599599
NoNodeStyles,
600600

601601
Monospace,
602+
DarkTheme,
602603
}
603604

604605
/// Returns vec holding all the default render options.
@@ -630,10 +631,23 @@ where
630631
writeln!(w, "digraph {} {{", g.graph_id().as_slice())?;
631632

632633
// Global graph properties
634+
let mut graph_attrs = Vec::new();
635+
let mut content_attrs = Vec::new();
633636
if options.contains(&RenderOption::Monospace) {
634-
writeln!(w, r#" graph[fontname="monospace"];"#)?;
635-
writeln!(w, r#" node[fontname="monospace"];"#)?;
636-
writeln!(w, r#" edge[fontname="monospace"];"#)?;
637+
let font = r#"fontname="Courier, monospace""#;
638+
graph_attrs.push(font);
639+
content_attrs.push(font);
640+
};
641+
if options.contains(&RenderOption::DarkTheme) {
642+
graph_attrs.push(r#"bgcolor="black""#);
643+
content_attrs.push(r#"color="white""#);
644+
content_attrs.push(r#"fontcolor="white""#);
645+
}
646+
if !(graph_attrs.is_empty() && content_attrs.is_empty()) {
647+
writeln!(w, r#" graph[{}];"#, graph_attrs.join(" "))?;
648+
let content_attrs_str = content_attrs.join(" ");
649+
writeln!(w, r#" node[{}];"#, content_attrs_str)?;
650+
writeln!(w, r#" edge[{}];"#, content_attrs_str)?;
637651
}
638652

639653
for n in g.nodes().iter() {

0 commit comments

Comments
 (0)