diff --git a/src/draw_target.rs b/src/draw_target.rs index d7af9f30..05e658b1 100644 --- a/src/draw_target.rs +++ b/src/draw_target.rs @@ -126,12 +126,12 @@ impl ProgressDrawTarget { } /// Returns the current width of the draw target. - pub(crate) fn width(&self) -> u16 { + pub(crate) fn width(&self) -> Option { match self.kind { - TargetKind::Term { ref term, .. } => term.size().1, + TargetKind::Term { ref term, .. } => Some(term.size().1), TargetKind::Multi { ref state, .. } => state.read().unwrap().width(), - TargetKind::Hidden => 0, - TargetKind::TermLike { ref inner, .. } => inner.width(), + TargetKind::TermLike { ref inner, .. } => Some(inner.width()), + TargetKind::Hidden => None, } } diff --git a/src/multi.rs b/src/multi.rs index 3cb4281b..7d287bfa 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -267,7 +267,12 @@ impl MultiState { if panicking() { return Ok(()); } - let width = self.width() as f64; + + let width = match self.width() { + Some(width) => width as f64, + None => return Ok(()), + }; + // Calculate real length based on terminal width // This take in account linewrap from terminal fn real_len(lines: &[String], width: f64) -> usize { @@ -393,7 +398,7 @@ impl MultiState { ret } - pub(crate) fn width(&self) -> u16 { + pub(crate) fn width(&self) -> Option { self.draw_target.width() } diff --git a/src/state.rs b/src/state.rs index 3bcdc445..3c55bb13 100644 --- a/src/state.rs +++ b/src/state.rs @@ -151,10 +151,13 @@ impl BarState { } else { draw_state.lines.extend(lines); } + draw_state.orphan_lines_count = draw_state.lines.len(); - if !matches!(self.state.status, Status::DoneHidden) { - self.style - .format_state(&self.state, &mut draw_state.lines, width); + if let Some(width) = width { + if !matches!(self.state.status, Status::DoneHidden) { + self.style + .format_state(&self.state, &mut draw_state.lines, width); + } } drop(draw_state); @@ -188,9 +191,11 @@ impl BarState { let mut draw_state = drawable.state(); - if !matches!(self.state.status, Status::DoneHidden) { - self.style - .format_state(&self.state, &mut draw_state.lines, width); + if let Some(width) = width { + if !matches!(self.state.status, Status::DoneHidden) { + self.style + .format_state(&self.state, &mut draw_state.lines, width); + } } drop(draw_state);