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 committed Oct 11, 2024
1 parent befc4c8 commit dde9132
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
28 changes: 11 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
.to_owned()
.into_iter()
.filter(|l| matches!(l, LineType::Text(_) | LineType::Empty)),
);
}
}
}
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 @@ -533,7 +534,9 @@ 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().fold(0, |acc, line| {
acc + matches!(line, LineType::Text(_) | LineType::Empty) as usize
});
// The number of bar lines that are contained in this draw state
// let bar_line_count = self.lines.len() - text_line_count;

Expand All @@ -545,14 +548,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()
);

if !self.lines.is_empty() && self.move_cursor {
// Move up to first line (assuming the last line doesn't contain a '\n') and then move to then front of the line
Expand Down Expand Up @@ -592,7 +587,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 @@ -629,7 +624,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 @@ -152,7 +152,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 dde9132

Please sign in to comment.