diff --git a/src/draw_target.rs b/src/draw_target.rs index 6c107d51..6d000a59 100644 --- a/src/draw_target.rs +++ b/src/draw_target.rs @@ -351,6 +351,14 @@ impl Drawable<'_> { } => draw_state.draw_to_term(term_like, last_line_count), } } + + pub(crate) fn width(&self) -> Option { + match self { + Drawable::Term { term, .. } => Some(term.size().1), + Drawable::Multi { state, .. } => state.width(), + Drawable::TermLike { term_like, .. } => Some(term_like.width()), + } + } } pub(crate) enum LineAdjust { diff --git a/src/state.rs b/src/state.rs index cd3c2d17..a98ca1b5 100644 --- a/src/state.rs +++ b/src/state.rs @@ -187,16 +187,14 @@ impl BarState { // finished progress bars, so it's kept as to not cause compatibility issues in weird cases. force_draw |= self.state.is_finished(); - // First check whether there is something to be drawn. - if self.draw_target.drawable(force_draw, now).is_none() { - return Ok(()); - } - // Then, get the target width. - // This is an expensive operation, and should only happen when we actually do some work. - let width = self.draw_target.width(); + // let width = self.draw_target.width(); + + let mut drawable = match self.draw_target.drawable(force_draw, now) { + Some(drawable) => drawable, + None => return Ok(()), + }; - // Now actually get the drawable. - let mut drawable = self.draw_target.drawable(force_draw, now).unwrap(); + let width = drawable.width(); let mut draw_state = drawable.state(); @@ -206,7 +204,6 @@ impl BarState { .format_state(&self.state, &mut draw_state.lines, width); } } - drop(draw_state); drawable.draw()