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 8b68e1ea..d5a54661 100644 --- a/src/state.rs +++ b/src/state.rs @@ -183,16 +183,17 @@ impl BarState { } pub(crate) fn draw(&mut self, mut force_draw: bool, now: Instant) -> io::Result<()> { - let width = self.draw_target.width(); - // `|= self.is_finished()` should not be needed here, but we used to always draw for // finished progress bars, so it's kept as to not cause compatibility issues in weird cases. force_draw |= self.state.is_finished(); + let mut drawable = match self.draw_target.drawable(force_draw, now) { Some(drawable) => drawable, None => return Ok(()), }; + let width = drawable.width(); + let mut draw_state = drawable.state(); if let Some(width) = width { @@ -201,7 +202,6 @@ impl BarState { .format_state(&self.state, &mut draw_state.lines, width); } } - drop(draw_state); drawable.draw() }