Skip to content

Commit 1d04eab

Browse files
committed
Merge branch 'master' into hooks
2 parents 11d4c09 + dc938ea commit 1d04eab

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/lib.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
//! * [DOT language](http://www.graphviz.org/doc/info/lang.html)
273273
274274
#![doc(
275-
html_root_url = "https://doc.rust-lang.org/nightly/",
275+
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
276276
test(attr(allow(unused_variables), deny(warnings)))
277277
)]
278278
#![feature(nll)]
@@ -591,14 +591,15 @@ pub trait GraphWalk<'a> {
591591
fn target(&'a self, edge: &Self::Edge) -> Self::Node;
592592
}
593593

594-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
594+
#[derive(Clone, PartialEq, Eq, Debug)]
595595
pub enum RenderOption {
596596
NoEdgeLabels,
597597
NoNodeLabels,
598598
NoEdgeStyles,
599599
NoNodeStyles,
600600

601-
Monospace,
601+
Fontname(String),
602+
DarkTheme,
602603
}
603604

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

632633
// Global graph properties
633-
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"];"#)?;
634+
let mut graph_attrs = Vec::new();
635+
let mut content_attrs = Vec::new();
636+
let font;
637+
if let Some(fontname) = options.iter().find_map(|option| {
638+
if let RenderOption::Fontname(fontname) = option { Some(fontname) } else { None }
639+
}) {
640+
font = format!(r#"fontname="{}""#, fontname);
641+
graph_attrs.push(&font[..]);
642+
content_attrs.push(&font[..]);
643+
}
644+
if options.contains(&RenderOption::DarkTheme) {
645+
graph_attrs.push(r#"bgcolor="black""#);
646+
content_attrs.push(r#"color="white""#);
647+
content_attrs.push(r#"fontcolor="white""#);
648+
}
649+
if !(graph_attrs.is_empty() && content_attrs.is_empty()) {
650+
writeln!(w, r#" graph[{}];"#, graph_attrs.join(" "))?;
651+
let content_attrs_str = content_attrs.join(" ");
652+
writeln!(w, r#" node[{}];"#, content_attrs_str)?;
653+
writeln!(w, r#" edge[{}];"#, content_attrs_str)?;
637654
}
638655

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

0 commit comments

Comments
 (0)