init
This commit is contained in:
115
src/main.rs
Normal file
115
src/main.rs
Normal file
@@ -0,0 +1,115 @@
|
||||
use std::{collections::HashMap, thread::sleep, time::Duration};
|
||||
|
||||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||
|
||||
use crate::action::StartFields;
|
||||
|
||||
pub mod action;
|
||||
pub mod action_raw;
|
||||
fn main() -> Result<(), color_eyre::Report> {
|
||||
color_eyre::install().unwrap();
|
||||
let lines = std::fs::read_to_string("log2")?;
|
||||
// let lines = lines.lines().take(1000).collect::<Vec<_>>().join("\n");
|
||||
|
||||
let progress = MultiProgress::new();
|
||||
let lines_pb = progress.add(ProgressBar::new(lines.lines().count() as u64));
|
||||
// progress.println("Parsing build.log...")?;
|
||||
// let pb1 = progress.add(ProgressBar::new(lines.lines().count() as u64));
|
||||
// pb1.set_style(
|
||||
// ProgressStyle::default_spinner()
|
||||
// .template("[{elapsed_precise:>6}] {msg}")
|
||||
// .unwrap(),
|
||||
// );
|
||||
// pb1.set_message("Processing line2342s\n|\n|\n>");
|
||||
// let pb2 = progress.add(ProgressBar::new(lines.lines().count() as u64));
|
||||
// pb2.set_style(
|
||||
// ProgressStyle::default_spinner()
|
||||
// .template("[{elapsed_precise:>6}] {msg}")
|
||||
// .unwrap(),
|
||||
// );
|
||||
// pb2.set_message("Processing line2342s\n|\n|\n>");
|
||||
// sleep(Duration::from_secs(1));
|
||||
|
||||
let mut map = HashMap::new();
|
||||
|
||||
for line in lines.lines() {
|
||||
lines_pb.inc(1);
|
||||
let line = line.strip_prefix("@nix ").unwrap_or(line);
|
||||
// sleep(Duration::from_millis(5));
|
||||
let action = action::Action::parse(line)?;
|
||||
match action {
|
||||
action::Action::Msg { level, msg } => {
|
||||
progress.println(format!("MSG (level {level}): {msg}"))?;
|
||||
}
|
||||
action::Action::Start {
|
||||
start_type,
|
||||
id,
|
||||
level,
|
||||
parent,
|
||||
text,
|
||||
} => match start_type {
|
||||
StartFields::CopyPath {
|
||||
path,
|
||||
origin,
|
||||
destination,
|
||||
} => {
|
||||
progress.println(format!(
|
||||
"START (id: {}, level: {}, parent: {}): CopyPath - {} (from: {}, to: {})",
|
||||
id, level, parent, text, origin, destination
|
||||
))?;
|
||||
}
|
||||
StartFields::FileTransfer { target } => {
|
||||
let bar = progress.add(ProgressBar::new(100));
|
||||
bar.set_style(
|
||||
ProgressStyle::default_bar()
|
||||
.template("{msg} [{bar:40.cyan/blue}] {pos:>3}%")
|
||||
.unwrap(),
|
||||
);
|
||||
bar.set_message(format!("meow {id} "));
|
||||
map.insert(id, bar);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
action::Action::Stop { id } => {
|
||||
if let Some(bar) = map.get(&id) {
|
||||
bar.finish();
|
||||
// bar.finish_with_message(format!("Transfer stopped (id: {})", id));
|
||||
progress.remove(bar);
|
||||
map.remove(&id);
|
||||
}
|
||||
// progress.println(format!("STOP (id: {})", id))?;
|
||||
}
|
||||
action::Action::Result { id, fields } => {
|
||||
// progress.println(format!("RESULT (id: {}): {:?}", id, fields))?;
|
||||
match fields {
|
||||
action::ResultFields::Progress {
|
||||
done,
|
||||
expected,
|
||||
running,
|
||||
failed,
|
||||
} => {
|
||||
sleep(Duration::from_millis(1));
|
||||
if let Some(bar) = map.get(&id) {
|
||||
let percentage = if expected == 0 {
|
||||
0
|
||||
} else {
|
||||
(done * 100 / expected) as u64
|
||||
};
|
||||
bar.set_position(percentage);
|
||||
// if done >= expected {
|
||||
// bar.finish_with_message(format!("Completed transfer (id: {})", id));
|
||||
// map.remove(&id);
|
||||
// }
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
println!("{action:#?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user