Skip to content

Commit

Permalink
Rust 2018 conventions (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers authored Dec 19, 2020
1 parent cde265b commit 34ebb16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "pbr"
version = "1.0.3"
authors = ["Ariel Mashraki <ariel@mashraki.co.il>", "Steven Fackler <sfackler@gmail.com>"]
edition = "2018"
description = "Console progress bar for Rust"
documentation = "http://a8m.github.io/pb/doc/pbr/index.html"
repository = "https://github.com/a8m/pb"
Expand Down
14 changes: 7 additions & 7 deletions src/multi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crossbeam_channel::{unbounded, Sender, Receiver};
use pb::ProgressBar;
use crate::tty::move_cursor_up;
use crate::ProgressBar;
use crossbeam_channel::{unbounded, Receiver, Sender};
use std::io::{Result, Stdout, Write};
use std::str::from_utf8;
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};
use tty::move_cursor_up;
use std::sync::Mutex;

pub struct MultiBar<T: Write> {
state: Mutex<State<T>>,
Expand All @@ -15,7 +15,7 @@ pub struct MultiBar<T: Write> {
struct State<T: Write> {
lines: Vec<String>,
nlines: usize,
handle: T
handle: T,
}

impl MultiBar<Stdout> {
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<T: Write> MultiBar<T> {
/// ```
pub fn create_bar(&self, total: u64) -> ProgressBar<Pipe> {
let mut state = self.state.lock().unwrap();

state.lines.push(String::new());
state.nlines += 1;

Expand All @@ -169,7 +169,7 @@ impl<T: Write> MultiBar<T> {
},
total,
);

p.is_multibar = true;
p.add(0);
p
Expand Down
14 changes: 5 additions & 9 deletions src/pb.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::tty::{terminal_size, Width};
use std::io::Stdout;
use std::io::{self, Write};
use std::iter::repeat;
use std::time::Duration;
use time::{self, SteadyTime};
use tty::{terminal_size, Width};

macro_rules! kb_fmt {
($n: ident) => {{
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<T: Write> ProgressBar<T> {
pub fn reset_start_time(&mut self) {
self.start_time = SteadyTime::now();
}

fn draw(&mut self) {
let now = SteadyTime::now();
if let Some(mrr) = self.max_refresh_rate {
Expand Down Expand Up @@ -507,7 +507,7 @@ fn fract_dur(d: Duration) -> f64 {

#[cfg(test)]
mod test {
use pb::{ProgressBar, Units};
use crate::{ProgressBar, Units};
use std::time::Duration;

#[test]
Expand Down Expand Up @@ -636,15 +636,11 @@ mod test {
.split('\r');
assert_eq!(
split.next(),
Some(
"250 / 500 ╢▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟ 50.00 %"
)
Some("250 / 500 ╢▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟ 50.00 %")
);
assert_eq!(
split.next(),
Some(
"500 / 500 ╢▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌╟ 100.00 %"
)
Some("500 / 500 ╢▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌╟ 100.00 %")
);
}
}

0 comments on commit 34ebb16

Please sign in to comment.