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

Only get draw_target-width when we actually draw #683

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 8 additions & 0 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ impl Drawable<'_> {
} => draw_state.draw_to_term(term_like, last_line_count),
}
}

pub(crate) fn width(&self) -> Option<u16> {
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 {
Expand Down
6 changes: 3 additions & 3 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -201,7 +202,6 @@ impl BarState {
.format_state(&self.state, &mut draw_state.lines, width);
}
}

drop(draw_state);
drawable.draw()
}
Expand Down
Loading