mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Refactor: Progress bar: Remove PConfig
This commit is contained in:
@@ -4,7 +4,6 @@ use std::sync::Arc;
|
|||||||
use crate::node::Node;
|
use crate::node::Node;
|
||||||
use crate::progress;
|
use crate::progress;
|
||||||
use crate::progress::PAtomicInfo;
|
use crate::progress::PAtomicInfo;
|
||||||
use crate::progress::PConfig;
|
|
||||||
use crate::progress::ThreadSyncMathTrait;
|
use crate::progress::ThreadSyncMathTrait;
|
||||||
use crate::progress::ThreadSyncTrait;
|
use crate::progress::ThreadSyncTrait;
|
||||||
use crate::utils::is_filtered_out_due_to_invert_regex;
|
use crate::utils::is_filtered_out_due_to_invert_regex;
|
||||||
@@ -32,7 +31,6 @@ pub struct WalkData<'a> {
|
|||||||
pub by_filecount: bool,
|
pub by_filecount: bool,
|
||||||
pub ignore_hidden: bool,
|
pub ignore_hidden: bool,
|
||||||
pub follow_links: bool,
|
pub follow_links: bool,
|
||||||
pub progress_config: Option<Arc<PConfig>>,
|
|
||||||
pub progress_data: Option<Arc<PAtomicInfo>>,
|
pub progress_data: Option<Arc<PAtomicInfo>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-11
@@ -13,7 +13,6 @@ mod utils;
|
|||||||
use crate::cli::build_cli;
|
use crate::cli::build_cli;
|
||||||
use dir_walker::WalkData;
|
use dir_walker::WalkData;
|
||||||
use filter::AggregateData;
|
use filter::AggregateData;
|
||||||
use progress::PConfig;
|
|
||||||
use progress::PIndicator;
|
use progress::PIndicator;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
@@ -178,19 +177,13 @@ fn main() {
|
|||||||
let info_indicator = if disable_progress {
|
let info_indicator = if disable_progress {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let conf = PConfig {
|
let mut indicator = PIndicator::build_me();
|
||||||
use_iso: iso,
|
indicator.spawn(iso);
|
||||||
};
|
|
||||||
let mut indicator = PIndicator::build_me(conf);
|
|
||||||
indicator.spawn();
|
|
||||||
Some(indicator)
|
Some(indicator)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Must be a cleaner way to do this
|
// Must be a cleaner way to do this
|
||||||
let (tmp_config, tmp_data) = match &info_indicator {
|
let tmp_data = info_indicator.as_ref().map(|i| Arc::clone(&i.data));
|
||||||
Some(i) => (Some(Arc::clone(&i.config)), Some(Arc::clone(&i.data))),
|
|
||||||
None => (None, None),
|
|
||||||
};
|
|
||||||
|
|
||||||
let walk_data = WalkData {
|
let walk_data = WalkData {
|
||||||
ignore_directories: ignored_full_path,
|
ignore_directories: ignored_full_path,
|
||||||
@@ -202,7 +195,6 @@ fn main() {
|
|||||||
ignore_hidden,
|
ignore_hidden,
|
||||||
follow_links,
|
follow_links,
|
||||||
// Maybe just arc::clone the whole PIndicator and send that down here:
|
// Maybe just arc::clone the whole PIndicator and send that down here:
|
||||||
progress_config: tmp_config,
|
|
||||||
progress_data: tmp_data,
|
progress_data: tmp_data,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+10
-66
@@ -1,15 +1,14 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
|
||||||
io::Write,
|
io::Write,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
|
atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
|
||||||
Arc, RwLock,
|
Arc, RwLock,
|
||||||
},
|
},
|
||||||
thread::JoinHandle,
|
thread::JoinHandle,
|
||||||
time::{Duration},
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::display;
|
use crate::display::human_readable_number;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@@ -87,62 +86,13 @@ pub mod Operation {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PAtomicInfo {
|
pub struct PAtomicInfo {
|
||||||
|
// pub file_number: AtomicUsize::new(0),
|
||||||
pub file_number: AtomicU64Wrapper,
|
pub file_number: AtomicU64Wrapper,
|
||||||
pub total_file_size: TotalSize,
|
pub total_file_size: AtomicU64Wrapper,
|
||||||
pub state: AtomicU8Wrapper,
|
pub state: AtomicU8Wrapper,
|
||||||
pub current_path: ThreadStringWrapper,
|
pub current_path: ThreadStringWrapper,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PAtomicInfo {
|
|
||||||
fn new(c: &PConfig) -> Self {
|
|
||||||
Self {
|
|
||||||
total_file_size: TotalSize::new(c),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct TotalSize {
|
|
||||||
use_iso: bool,
|
|
||||||
inner: AtomicU64Wrapper,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TotalSize {
|
|
||||||
fn new(c: &PConfig) -> Self {
|
|
||||||
Self {
|
|
||||||
use_iso: c.use_iso,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for TotalSize {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.write_str(&display::human_readable_number(
|
|
||||||
self.inner.get(),
|
|
||||||
self.use_iso,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ThreadSyncTrait<u64> for TotalSize {
|
|
||||||
fn set(&self, val: u64) {
|
|
||||||
self.inner.set(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self) -> u64 {
|
|
||||||
self.inner.get()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ThreadSyncMathTrait<u64> for TotalSize {
|
|
||||||
fn add(&self, val: u64) {
|
|
||||||
self.inner.add(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
fn format_indicator_str(data: &PAtomicInfo, progress_char_i: usize, s: &str) -> String {
|
fn format_indicator_str(data: &PAtomicInfo, progress_char_i: usize, s: &str) -> String {
|
||||||
@@ -154,29 +104,22 @@ fn format_indicator_str(data: &PAtomicInfo, progress_char_i: usize, s: &str) ->
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct PConfig {
|
|
||||||
pub use_iso: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PIndicator {
|
pub struct PIndicator {
|
||||||
thread_run: Arc<AtomicBool>,
|
thread_run: Arc<AtomicBool>,
|
||||||
pub thread: Option<JoinHandle<()>>,
|
pub thread: Option<JoinHandle<()>>,
|
||||||
pub data: Arc<PAtomicInfo>,
|
pub data: Arc<PAtomicInfo>,
|
||||||
pub config: Arc<PConfig>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PIndicator {
|
impl PIndicator {
|
||||||
pub fn build_me(c: PConfig) -> Self {
|
pub fn build_me() -> Self {
|
||||||
Self {
|
Self {
|
||||||
thread_run: Arc::new(AtomicBool::new(true)),
|
thread_run: Arc::new(AtomicBool::new(true)),
|
||||||
thread: None,
|
thread: None,
|
||||||
data: Arc::new(PAtomicInfo::new(&c)),
|
data: Arc::new(PAtomicInfo{..Default::default()}),
|
||||||
config: Arc::new(c),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn(&mut self) {
|
pub fn spawn(&mut self, is_iso: bool) {
|
||||||
let data = self.data.clone();
|
let data = self.data.clone();
|
||||||
let is_building_data_const = self.thread_run.clone();
|
let is_building_data_const = self.thread_run.clone();
|
||||||
|
|
||||||
@@ -191,8 +134,9 @@ impl PIndicator {
|
|||||||
let base = format_indicator_str(&data, progress_char_i, "Indexing");
|
let base = format_indicator_str(&data, progress_char_i, "Indexing");
|
||||||
|
|
||||||
let file_count = data.file_number.get();
|
let file_count = data.file_number.get();
|
||||||
let file_str =
|
let size = human_readable_number(data.total_file_size.get(), is_iso);
|
||||||
format!("{} {} files", file_count, data.total_file_size);
|
let file_str = format!("{} {} files", file_count, size);
|
||||||
|
// let file_str = format!("{} {} files", file_count, data.total_file_size);
|
||||||
|
|
||||||
format!("{} - {}", base, file_str)
|
format!("{} - {}", base, file_str)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user