Skip to content

Commit 9f6b4f7

Browse files
quark-zjumeta-codesync[bot]
authored andcommitted
renderdag: skip separator line if rendered >1 lines for a row
Summary: Intended to fix the issue that D107317575 is fixing. But in a more general way. D107317575 only considered ending with blank lines. A more accurate test is if the previous row produces multiple lines. ___ Differential Revision: D107434238 fbshipit-source-id: c8ed6b8455c0d7e9099237adf29999e2cc22e9eb
1 parent 5edd836 commit 9f6b4f7

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

eden/scm/lib/renderdag/src/box_drawing.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ mod tests {
238238
o A"#
239239
);
240240

241-
// Suboptimal: extra blank line after C is unnecessary.
242241
assert_eq!(
243242
render(&TestFixture {
244243
messages: &[("C", "line 1\nline 2\n")],
@@ -249,7 +248,6 @@ mod tests {
249248
o C
250249
line 1
251250
line 2
252-
253251
o B
254252
255253
o A"#

eden/scm/lib/renderdag/src/output.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ pub struct OutputRendererOptions {
2626
#[derive(Default)]
2727
pub(crate) struct OutputRendererState {
2828
queued_pad_line: Option<String>,
29-
last_line_is_blank: bool,
29+
/// If > 1, no need for an extra separator for the next row.
30+
/// Separator is only needed for adjacent single-line node lines.
31+
/// If there are link, pad, term, or other kinds of node lines,
32+
/// no need to draw separator.
33+
row_height: usize,
3034
}
3135

3236
impl OutputRendererState {
3337
pub(crate) fn begin_row(&mut self, out: &mut String, separator_line: bool) {
3438
self.flush_queued_pad_line(out);
35-
if separator_line {
36-
self.maybe_push_separator_line(out);
39+
if separator_line && self.row_height == 1 {
40+
self.push_line(out, "");
3741
}
42+
self.row_height = 0;
3843
}
3944

4045
pub(crate) fn push_line_with_message(
@@ -75,14 +80,7 @@ impl OutputRendererState {
7580
fn push_line(&mut self, out: &mut String, line: &str) {
7681
out.push_str(line.trim_end());
7782
out.push('\n');
78-
self.last_line_is_blank = line.trim_end().is_empty();
79-
}
80-
81-
fn maybe_push_separator_line(&mut self, out: &mut String) {
82-
if !self.last_line_is_blank {
83-
out.push('\n');
84-
self.last_line_is_blank = true;
85-
}
83+
self.row_height = self.row_height.saturating_add(1);
8684
}
8785

8886
fn flush_queued_pad_line(&mut self, out: &mut String) {

0 commit comments

Comments
 (0)