Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip drawing MultiProgress if backing draw target is hidden #603

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16> {
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,
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -393,7 +398,7 @@ impl MultiState {
ret
}

pub(crate) fn width(&self) -> u16 {
pub(crate) fn width(&self) -> Option<u16> {
self.draw_target.width()
}

Expand Down
17 changes: 11 additions & 6 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down