Skip to content

Commit

Permalink
Sunset confusingly named, obsolete external count
Browse files Browse the repository at this point in the history
  • Loading branch information
spoutn1k authored and djc committed Nov 15, 2024
1 parent 590b704 commit d3cf542
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
30 changes: 13 additions & 17 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,13 @@ impl std::ops::DerefMut for DrawStateWrapper<'_> {
impl Drop for DrawStateWrapper<'_> {
fn drop(&mut self) {
if let Some(orphaned) = &mut self.orphan_lines {
orphaned.extend(self.state.lines.drain(..self.state.orphan_lines_count));
self.state.orphan_lines_count = 0;
orphaned.extend(
self.state
.lines
.iter()
.filter(|l| matches!(l, LineType::Text(_) | LineType::Empty))
.cloned(),
);
}
}
}
Expand Down Expand Up @@ -461,10 +466,6 @@ const MAX_BURST: u8 = 20;
pub(crate) struct DrawState {
/// The lines to print (can contain ANSI codes)
pub(crate) lines: Vec<LineType>,
/// The number [`Self::lines`] entries that shouldn't be reaped by the next tick.
///
/// Note that this number may be different than the number of visual lines required to draw [`Self::lines`].
pub(crate) orphan_lines_count: usize,
/// True if we should move the cursor up when possible instead of clearing lines.
pub(crate) move_cursor: bool,
/// Controls how the multi progress is aligned if some of its progress bars get removed, default is `Top`
Expand Down Expand Up @@ -505,7 +506,11 @@ impl DrawState {
let term_width = term.width() as usize;

// The number of text lines that are contained in this draw state
let text_line_count = self.orphan_lines_count;
let text_line_count = self
.lines
.iter()
.filter(|line| matches!(line, LineType::Text(_) | LineType::Empty))
.count();

// Here we calculate the terminal vertical height each of those groups require when
// printing, taking wrapping into account.
Expand All @@ -515,14 +520,6 @@ impl DrawState {

// Sanity checks
debug_assert!(full_height == text_height + bar_height);
debug_assert!(
self.orphan_lines_count
== self
.lines
.iter()
.filter(|l| matches!(l, LineType::Text(_) | LineType::Empty))
.count()
);

let shift = match self.alignment {
// If we align to the bottom and the new height is less than before, clear the lines
Expand All @@ -546,7 +543,7 @@ impl DrawState {
let line_height = line.wrapped_height(term_width);

// Check here for bar lines that exceed the terminal height
if self.orphan_lines_count <= idx {
if text_line_count <= idx {
// If all the orphan lines have been drawn, then `real_height` should be
// at least `orphan_visual_line_count`.
debug_assert!(text_height <= real_height);
Expand Down Expand Up @@ -583,7 +580,6 @@ impl DrawState {

fn reset(&mut self) {
self.lines.clear();
self.orphan_lines_count = 0;
}

pub(crate) fn visual_line_count(
Expand Down
2 changes: 0 additions & 2 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,10 @@ impl MultiState {
};

let mut draw_state = drawable.state();
draw_state.orphan_lines_count = self.orphan_lines.len();
draw_state.alignment = self.alignment;

if let Some(extra_lines) = &extra_lines {
draw_state.lines.extend_from_slice(extra_lines.as_slice());
draw_state.orphan_lines_count += extra_lines.len();
}

// Add lines from `ProgressBar::println` call.
Expand Down
1 change: 0 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl BarState {
draw_state.lines.extend(lines);
}

draw_state.orphan_lines_count = draw_state.lines.len();
if let Some(width) = width {
if !matches!(self.state.status, Status::DoneHidden) {
self.style
Expand Down

0 comments on commit d3cf542

Please sign in to comment.