Skip to content

Commit

Permalink
Pull line push into separate function
Browse files Browse the repository at this point in the history
This pulls the part of format_style that
appends a new line to the progress into
a separate function, which can be used
to transform the expanded line content
before it is added.
  • Loading branch information
happenslol committed Sep 17, 2022
1 parent 791068c commit 271ebbd
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,24 +359,31 @@ impl ProgressStyle {
}
}
TemplatePart::Literal(s) => cur.push_str(s.expanded()),
TemplatePart::NewLine => lines.push(match wide {
Some(inner) => {
inner.expand(mem::take(&mut cur), self, state, &mut buf, target_width)
}
None => mem::take(&mut cur),
}),
TemplatePart::NewLine => {
self.push_line(lines, &mut cur, state, &mut buf, target_width, &wide)
}
}
}

if !cur.is_empty() {
lines.push(match wide {
Some(inner) => {
inner.expand(mem::take(&mut cur), self, state, &mut buf, target_width)
}
None => mem::take(&mut cur),
})
self.push_line(lines, &mut cur, state, &mut buf, target_width, &wide);
}
}

fn push_line(
&self,
lines: &mut Vec<String>,
cur: &mut String,
state: &ProgressState,
buf: &mut String,
target_width: u16,
wide: &Option<WideElement>,
) {
lines.push(match wide {
Some(inner) => inner.expand(mem::take(cur), self, state, buf, target_width),
None => mem::take(cur),
});
}
}

struct TabRewriter<'a>(&'a mut dyn fmt::Write, usize);
Expand Down

0 comments on commit 271ebbd

Please sign in to comment.