Debian Codegraph @

src/ascii.rs

raw symbols SCIP
1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
9
10 use itertoolsrust-analyzer cargo itertools 0.15.0 crate/::Itertoolsrust-analyzer cargo itertools 0.15.0 Itertools#;
11
12 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::outputrust-analyzer cargo esl01-renderdag 0.3.0 output/::OutputRendererOptionsrust-analyzer cargo esl01-renderdag 0.3.0 output/OutputRendererOptions#;
13 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::renderrust-analyzer cargo esl01-renderdag 0.3.0 render/::Ancestorrust-analyzer cargo esl01-renderdag 0.3.0 render/Ancestor#;
14 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::renderrust-analyzer cargo esl01-renderdag 0.3.0 render/::GraphRowrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#;
15 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::renderrust-analyzer cargo esl01-renderdag 0.3.0 render/::LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#;
16 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::renderrust-analyzer cargo esl01-renderdag 0.3.0 render/::NodeLinerust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#;
17 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::renderrust-analyzer cargo esl01-renderdag 0.3.0 render/::PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#;
18 use superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::renderrust-analyzer cargo esl01-renderdag 0.3.0 render/::Rendererrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#;
19
20 pub struct AsciiRendererrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#<N, R>
21 where
22 R: Rendererrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#<N, Outputrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#Output# = GraphRowrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#<N>> + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
23 {
24 innerrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#inner.: R,
25 optionsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#options.: OutputRendererOptionsrust-analyzer cargo esl01-renderdag 0.3.0 output/OutputRendererOptions#,
26 extra_pad_linerust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#extra_pad_line.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
27 _phantomrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#_phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<N>,
28 }
29
30 impl<N, R> AsciiRendererrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#<N, R>
31 where
32 R: Rendererrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#<N, Outputrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#Output# = GraphRowrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#<N>> + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
33 {
34 pub(craterust-analyzer cargo esl01-renderdag 0.3.0 crate/) fn newrust-analyzer cargo esl01-renderdag 0.3.0 ascii/impl#[`AsciiRenderer<N, R>`]new().(inner: R, options: OutputRendererOptionsrust-analyzer cargo esl01-renderdag 0.3.0 output/OutputRendererOptions#) -> Selfrust-analyzer cargo esl01-renderdag 0.3.0 ascii/impl#[`AsciiRenderer<N, R>`] {
35 AsciiRendererrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer# {
36 innerrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#inner.,
37 optionsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#options.,
38 extra_pad_linerust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#extra_pad_line.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
39 _phantomrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#_phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
40 }
41 }
42 }
43
44 impl<N, R> Rendererrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#<N> for AsciiRendererrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#<N, R>
45 where
46 N: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#,
47 R: Rendererrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#<N, Outputrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#Output# = GraphRowrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#<N>> + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
48 {
49 type Outputrust-analyzer cargo esl01-renderdag 0.3.0 ascii/impl#[`AsciiRenderer<N, R>`][`Renderer<N>`]Output# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
50
51 fn widthrust-analyzer cargo esl01-renderdag 0.3.0 ascii/impl#[`AsciiRenderer<N, R>`][`Renderer<N>`]width().(&self, node: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&N>, parents: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Ancestorrust-analyzer cargo esl01-renderdag 0.3.0 render/Ancestor#<N>>>) -> u64 {
52 self.innerrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#inner.
53 .widthrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#width().(node, parents)
54 .saturating_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_mul().(2)
55 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_add().(1)
56 }
57
58 fn reserverust-analyzer cargo esl01-renderdag 0.3.0 ascii/impl#[`AsciiRenderer<N, R>`][`Renderer<N>`]reserve().(&mut self, node: N) {
59 self.innerrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#inner..reserverust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#reserve().(node);
60 }
61
62 fn next_rowrust-analyzer cargo esl01-renderdag 0.3.0 ascii/impl#[`AsciiRenderer<N, R>`][`Renderer<N>`]next_row().(
63 &mut self,
64 node: N,
65 parents: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Ancestorrust-analyzer cargo esl01-renderdag 0.3.0 render/Ancestor#<N>>,
66 glyph: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
67 message: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
68 ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
69 let line = self.innerrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#inner..next_rowrust-analyzer cargo esl01-renderdag 0.3.0 render/Renderer#next_row().(node, parents, glyph, message);
70 let mut out = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
71 let mut message_lines = line
72 .messagerust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#message.
73 .linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().()
74 .pad_usingrust-analyzer cargo itertools 0.15.0 Itertools#pad_using().(self.optionsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#options..min_row_heightrust-analyzer cargo esl01-renderdag 0.3.0 output/OutputRendererOptions#min_row_height., |_| "");
75 let mut need_extra_pad_line = false;
76
77 // Render the previous extra pad line
78 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(extra_pad_line) = self.extra_pad_linerust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#extra_pad_line..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
79 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(extra_pad_line.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().());
80 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
81 }
82
83 // Render the nodeline
84 let mut node_line = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
85 for entry in line.node_linerust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#node_line..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
86 match entry {
87 NodeLinerust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#::Noderust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#Node# => {
88 node_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&line.glyphrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#glyph.);
89 node_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
90 }
91 NodeLinerust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#::Parentrust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#Parent# => node_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("| "),
92 NodeLinerust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#::Ancestorrust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#Ancestor# => node_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(". "),
93 NodeLinerust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#::Blankrust-analyzer cargo esl01-renderdag 0.3.0 render/NodeLine#Blank# => node_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(" "),
94 }
95 }
96 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(msg) = message_lines.nextrust-analyzer cargo itertools 0.15.0 pad_tail/impl#[`PadUsing<I, F>`][Iterator]next().() {
97 node_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
98 node_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(msg);
99 }
100 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(node_line.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().());
101 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
102
103 // Render the link line
104 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(link_row) = line.link_linerust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#link_line. {
105 let mut link_line = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
106 let any_horizontal = link_row
107 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
108 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|cur| cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::HORIZONTALrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]HORIZONTAL.));
109 for (cur, next) in link_row
110 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
111 .chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::emptyrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]empty().()).iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]iter().())
112 .tuple_windowsrust-analyzer cargo itertools 0.15.0 Itertools#tuple_windows().()
113 {
114 // Draw the parent/ancestor line.
115 if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::HORIZONTALrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]HORIZONTAL.) {
116 if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::CHILDrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]CHILD. rust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine][`BitOr<Self>`]bitor().|rust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine][`BitOr<Self>`]bitor(). rust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine][`BitOr<Self>`]bitor().LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::ANY_FORK_OR_MERGErust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]ANY_FORK_OR_MERGE.) {
117 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('+');
118 } else {
119 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
120 }
121 } else if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::VERTICALrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]VERTICAL.) {
122 if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::ANY_FORK_OR_MERGErust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]ANY_FORK_OR_MERGE.) && any_horizontal {
123 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('+');
124 } else if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::VERT_PARENTrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]VERT_PARENT.) {
125 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('|');
126 } else {
127 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('.');
128 }
129 } else if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::ANY_MERGErust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]ANY_MERGE.) && any_horizontal {
130 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\'');
131 } else if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::ANY_FORKrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]ANY_FORK.) && any_horizontal {
132 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('.');
133 } else {
134 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
135 }
136
137 // Draw the connecting line.
138 if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::HORIZONTALrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]HORIZONTAL.) {
139 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
140 } else if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::RIGHT_MERGErust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]RIGHT_MERGE.) {
141 if next.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::LEFT_FORKrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]LEFT_FORK.) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().any_horizontal {
142 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\\');
143 } else {
144 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
145 }
146 } else if cur.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::RIGHT_FORKrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]RIGHT_FORK.) {
147 if next.intersectsrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]intersects().(LinkLinerust-analyzer cargo esl01-renderdag 0.3.0 render/LinkLine#::LEFT_MERGErust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[LinkLine]LEFT_MERGE.) && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().any_horizontal {
148 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('/');
149 } else {
150 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('-');
151 }
152 } else {
153 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
154 }
155 }
156 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(msg) = message_lines.nextrust-analyzer cargo itertools 0.15.0 pad_tail/impl#[`PadUsing<I, F>`][Iterator]next().() {
157 link_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
158 link_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(msg);
159 }
160 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(link_line.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().());
161 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
162 }
163
164 // Render the term line
165 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(term_row) = line.term_linerust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#term_line. {
166 let term_strs = ["| ", "~ "];
167 for term_str in term_strs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
168 let mut term_line = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
169 for (i, term) in term_row.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
170 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().term {
171 term_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(term_str);
172 } else {
173 term_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(match line.pad_linesrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#pad_lines.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). {
174 PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#::Parentrust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#Parent# => "| ",
175 PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#::Ancestorrust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#Ancestor# => ". ",
176 PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#::Blankrust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#Blank# => " ",
177 });
178 }
179 }
180 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(msg) = message_lines.nextrust-analyzer cargo itertools 0.15.0 pad_tail/impl#[`PadUsing<I, F>`][Iterator]next().() {
181 term_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
182 term_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(msg);
183 }
184 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(term_line.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().());
185 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
186 }
187 need_extra_pad_line = true;
188 }
189
190 let mut base_pad_line = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
191 for entry in line.pad_linesrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRow#pad_lines..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
192 base_pad_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(match entry {
193 PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#::Parentrust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#Parent# => "| ",
194 PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#::Ancestorrust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#Ancestor# => ". ",
195 PadLinerust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#::Blankrust-analyzer cargo esl01-renderdag 0.3.0 render/PadLine#Blank# => " ",
196 });
197 }
198
199 // Render any pad lines
200 for msg in message_lines {
201 let mut pad_line = base_pad_line.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().();
202 pad_line.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' ');
203 pad_line.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(msg);
204 out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(pad_line.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().());
205 out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
206 need_extra_pad_line = false;
207 }
208
209 if need_extra_pad_line {
210 self.extra_pad_linerust-analyzer cargo esl01-renderdag 0.3.0 ascii/AsciiRenderer#extra_pad_line. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_pad_line);
211 }
212
213 out
214 }
215 }
216
217 #[cfg(test)]
218 mod testsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/ {
219 use superrust-analyzer cargo esl01-renderdag 0.3.0 ascii/::superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/;
220 use superrust-analyzer cargo esl01-renderdag 0.3.0 ascii/::superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::TestFixturerust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/TestFixture#;
221 use superrust-analyzer cargo esl01-renderdag 0.3.0 ascii/::superrust-analyzer cargo esl01-renderdag 0.3.0 crate/::test_utilsrust-analyzer cargo esl01-renderdag 0.3.0 test_utils/::render_stringrust-analyzer cargo esl01-renderdag 0.3.0 test_utils/render_string().;
222 use craterust-analyzer cargo esl01-renderdag 0.3.0 crate/::GraphRowRendererrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRowRenderer#;
223
224 fn renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(fixture: &TestFixturerust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/TestFixture#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
225 let mut renderer = GraphRowRendererrust-analyzer cargo esl01-renderdag 0.3.0 render/GraphRowRenderer#::newrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[`GraphRowRenderer<N>`]new().().outputrust-analyzer cargo esl01-renderdag 0.3.0 render/impl#[`GraphRowRenderer<N>`]output().().build_asciirust-analyzer cargo esl01-renderdag 0.3.0 output/impl#[`OutputRendererBuilder<N, R>`]build_ascii().();
226 render_stringrust-analyzer cargo esl01-renderdag 0.3.0 test_utils/render_string().(fixture, &mut renderer)
227 }
228
229 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
230 fn basicrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/basic().() {
231 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
232 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::BASICrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/BASIC.),
233 r#"
234 o C
235 |
236 o B
237 |
238 o A"#
239 );
240 }
241
242 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
243 fn branches_and_mergesrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/branches_and_merges().() {
244 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
245 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::BRANCHES_AND_MERGESrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/BRANCHES_AND_MERGES.),
246 r#"
247 o W
248 |
249 o V
250 |\
251 | o U
252 | |\
253 | | o T
254 | | |
255 | o | S
256 | |
257 o | R
258 | |
259 o | Q
260 |\ |
261 | o | P
262 | +---.
263 | | | o O
264 | | | |
265 | | | o N
266 | | | |\
267 | o | | | M
268 | | | | |
269 | o | | | L
270 | | | | |
271 o | | | | K
272 +-------'
273 o | | | J
274 | | | |
275 o | | | I
276 |/ | |
277 o | | H
278 | | |
279 o | | G
280 +-----+
281 | | o F
282 | |/
283 | o E
284 | |
285 o | D
286 | |
287 o | C
288 +---'
289 o B
290 |
291 o A"#
292 );
293 }
294
295 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
296 fn octopus_branch_and_mergerust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/octopus_branch_and_merge().() {
297 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
298 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::OCTOPUS_BRANCH_AND_MERGErust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/OCTOPUS_BRANCH_AND_MERGE.),
299 r#"
300 o J
301 +-+-.
302 | | o I
303 | | |
304 | o | H
305 +-+-+-+-.
306 | | | | o G
307 | | | | |
308 | | | o | E
309 | | | |/
310 | | o | D
311 | | |\|
312 | o | | C
313 | +---'
314 o | | F
315 |/ |
316 o | B
317 +---'
318 o A"#
319 );
320 }
321
322 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
323 fn reserved_columnrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/reserved_column().() {
324 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
325 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::RESERVED_COLUMNrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/RESERVED_COLUMN.),
326 r#"
327 o Z
328 |
329 o Y
330 |
331 o X
332 /
333 | o W
334 |/
335 o G
336 |
337 o F
338 |\
339 | o E
340 | |
341 | o D
342 |
343 o C
344 |
345 o B
346 |
347 o A"#
348 );
349 }
350
351 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
352 fn ancestorsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/ancestors().() {
353 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
354 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::ANCESTORSrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/ANCESTORS.),
355 r#"
356 o Z
357 |
358 o Y
359 /
360 o F
361 .
362 . o X
363 ./
364 | o W
365 |/
366 o E
367 .
368 o D
369 |\
370 | o C
371 | .
372 o . B
373 |/
374 o A"#
375 );
376 }
377
378 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
379 fn split_parentsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/split_parents().() {
380 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
381 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::SPLIT_PARENTSrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/SPLIT_PARENTS.),
382 r#"
383 o E
384 .-+-+-+
385 . o | . D
386 ./ \| .
387 | o . C
388 | |/
389 o | B
390 +---'
391 o A"#
392 );
393 }
394
395 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
396 fn terminationsrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/terminations().() {
397 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
398 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::TERMINATIONSrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/TERMINATIONS.),
399 r#"
400 o K
401 |
402 | o J
403 |/
404 o I
405 /|\
406 | | |
407 | ~ |
408 | |
409 o | E
410 | |
411 | o H
412 +---'
413 o D
414 |
415 ~
416
417 o C
418 |
419 o B
420 |
421 ~"#
422 );
423 }
424
425 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
426 fn long_messagesrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/long_messages().() {
427 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
428 renderrust-analyzer cargo esl01-renderdag 0.3.0 ascii/tests/render().(&test_fixturesrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/::LONG_MESSAGESrust-analyzer cargo esl01-renderdag 0.3.0 test_fixtures/LONG_MESSAGES.),
429 r#"
430 o F
431 +-+-. very long message 1
432 | | | very long message 2
433 | | ~ very long message 3
434 | |
435 | | very long message 4
436 | | very long message 5
437 | | very long message 6
438 | |
439 | o E
440 | |
441 | o D
442 | |
443 o | C
444 |/ long message 1
445 | long message 2
446 | long message 3
447 |
448 o B
449 |
450 o A
451 | long message 1
452 ~ long message 2
453 long message 3"#
454 );
455 }
456 }