Skip to content

Commit

Permalink
Merge pull request #13 from a8m/fix/issue-11
Browse files Browse the repository at this point in the history
Fix drawing logic. issue #11
  • Loading branch information
a8m committed May 17, 2016
2 parents 72b577c + b403d6b commit ee5f3f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl ProgressBar {
};
}
// time left box
if self.show_time_left {
if self.show_time_left && self.current > 0 {
if self.total > self.current {
let left = 1. / speed * (self.total - self.current) as f64;
if left < 60. {
Expand Down Expand Up @@ -299,7 +299,7 @@ impl ProgressBar {
.ceil() as usize;
let rema_count = size - curr_count;
base = self.bar_start.clone();
if rema_count > 0 {
if rema_count > 0 && curr_count > 0 {
base = base + repeat!(self.bar_current.as_ref(), curr_count - 1) +
&self.bar_current_n;
} else {
Expand Down
26 changes: 22 additions & 4 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn simple_example() {
}

#[test]
fn simple_iter_example(){
fn simple_iter_example() {
for _ in PbIter::new(0..20000) {
thread::sleep(Duration::from_millis(1));
}
Expand All @@ -27,7 +27,7 @@ fn simple_iter_example(){
#[test]
fn timeout_example() {
let count = 10;
let mut pb = ProgressBar::new(count*20);
let mut pb = ProgressBar::new(count * 20);
pb.tick_format("▏▎▍▌▋▊▉██▉▊▋▌▍▎▏");
pb.show_message = true;
pb.inc();
Expand All @@ -52,10 +52,28 @@ fn timeout_example() {
println!("done!");
}


#[test]
// see: issue #11
fn tick_before_start() {
let count = 100;
let mut pb = ProgressBar::new(count);
pb.tick_format("▏▎▍▌▋▊▉██▉▊▋▌▍▎▏");
pb.tick();
for _ in 0..count {
pb.tick();
thread::sleep(Duration::from_millis(50));
}
for _ in 0..count {
pb.inc();
thread::sleep(Duration::from_millis(50));
}
}

#[test]
fn npm_bar() {
let count = 30;
let mut pb = ProgressBar::new(count*5);
let count = 30;
let mut pb = ProgressBar::new(count * 5);
pb.tick_format("\\|/-");
pb.format("|#--|");
pb.show_tick = true;
Expand Down

0 comments on commit ee5f3f0

Please sign in to comment.