MCPcopy Create free account
hub / github.com/andreiverse/gorilla / printer_blocking

Function printer_blocking

src/threading.rs:58–139  ·  view source on GitHub ↗
(
    no_progress_bar: bool,
    start_time: SystemTime,
    output_separator: String,
    total_words: Arc<AtomicUsize>,
    file_save_path: Option<String>,
    show_header: bool,
    rx: Receiver<St

Source from the content-addressed store, hash-verified

56}
57
58pub fn printer_blocking(
59 no_progress_bar: bool,
60 start_time: SystemTime,
61 output_separator: String,
62 total_words: Arc<AtomicUsize>,
63 file_save_path: Option<String>,
64 show_header: bool,
65 rx: Receiver<String>,
66) {
67 let mut printer_stats = PrinterStats { saved_words: 0 };
68
69 let mut writer: Box<dyn io::Write> = if let Some(path) = file_save_path {
70 let file = File::create(path).expect("Unable to create file");
71 Box::new(BufWriter::new(file))
72 } else {
73 Box::new(BufWriter::new(io::stdout()))
74 };
75
76 // Initial load
77 let total_count = total_words.load(Ordering::Relaxed);
78
79 let pb = ProgressBar::new(total_count as u64);
80
81 // {spinner} = animated spinner
82 // {bar:40.cyan/blue} = a 40-char wide bar colored cyan/blue
83 // {pos}/{len} = current/total
84 // {eta} = estimated time remaining
85 pb.set_style(
86 ProgressStyle::default_bar()
87 .template("gorilla: (wrk) {spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} (eta: {eta}) {msg}")
88 .unwrap()
89 .progress_chars("#>-"),
90 );
91
92 if no_progress_bar {
93 pb.set_draw_target(ProgressDrawTarget::hidden());
94 } else {
95 pb.set_draw_target(ProgressDrawTarget::stderr());
96 }
97
98 for mutated_word in rx {
99 if show_header && printer_stats.saved_words < 5 {
100 pb.suspend(|| {
101 logging::info(&format!(
102 "(gen #{}) {}",
103 printer_stats.saved_words, mutated_word
104 ));
105 })
106 }
107
108 printer_stats.saved_words += 1;
109
110 pb.inc(1);
111
112 // Check for updates to total_words
113 let current_total = total_words.load(Ordering::Relaxed) as u64;
114 if current_total != pb.length().unwrap_or(0) {
115 pb.set_length(current_total);

Callers 1

printer_threadFunction · 0.85

Calls 3

infoFunction · 0.85
errorFunction · 0.85
successFunction · 0.85

Tested by

no test coverage detected