more reworking bar + new log format
This commit is contained in:
180376
1763196716.log
Normal file
180376
1763196716.log
Normal file
File diff suppressed because it is too large
Load Diff
86558
1763196781.log
Normal file
86558
1763196781.log
Normal file
File diff suppressed because it is too large
Load Diff
1534
1763197645.log
Normal file
1534
1763197645.log
Normal file
File diff suppressed because it is too large
Load Diff
1997
1763197700.log
Normal file
1997
1763197700.log
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,13 @@
|
|||||||
cargo-features = ["codegen-backend"]
|
cargo-features = ["codegen-backend"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "record"
|
||||||
|
path = "src/bin/record.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "main"
|
||||||
|
path = "src/bin/main.rs"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "nix-output"
|
name = "nix-output"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
cargo-nextest
|
cargo-nextest
|
||||||
cargo-valgrind
|
cargo-valgrind
|
||||||
pkg-config
|
pkg-config
|
||||||
nix.dev
|
# nix.dev
|
||||||
boost.dev
|
boost.dev
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
33
src/bin/main.rs
Normal file
33
src/bin/main.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use color_eyre::eyre::ContextCompat;
|
||||||
|
use console::Term;
|
||||||
|
use nix_output::action;
|
||||||
|
use nix_output::state::State;
|
||||||
|
|
||||||
|
fn main() -> Result<(), color_eyre::Report> {
|
||||||
|
color_eyre::install().unwrap();
|
||||||
|
let mut args = std::env::args().skip(1);
|
||||||
|
let first = args.next().context("Failed to get first arg")?;
|
||||||
|
|
||||||
|
let lines = std::fs::read_to_string(first)?;
|
||||||
|
let mut state = State::new(Term::stderr().size().1);
|
||||||
|
let start = Instant::now();
|
||||||
|
for line in lines.lines() {
|
||||||
|
let mut time = line.split("~");
|
||||||
|
let instant = time.next().unwrap(); // impossible to fail
|
||||||
|
let instant: u128 = instant.parse()?;
|
||||||
|
let elapsed = start.elapsed().as_millis();
|
||||||
|
if instant > elapsed {
|
||||||
|
sleep(Duration::from_millis(instant.saturating_sub(elapsed) as u64));
|
||||||
|
}
|
||||||
|
|
||||||
|
let line = time.collect::<String>();
|
||||||
|
let line = line.strip_prefix("@nix ").unwrap_or(&line);
|
||||||
|
let action = action::Action::parse(line)?;
|
||||||
|
state.handle(&action)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
27
src/bin/record.rs
Normal file
27
src/bin/record.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use core::time;
|
||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::{BufRead, BufReader, Write},
|
||||||
|
time::{Instant, SystemTime},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() -> Result<(), color_eyre::Report> {
|
||||||
|
color_eyre::install().unwrap();
|
||||||
|
let stderr = std::io::stdin();
|
||||||
|
let mut lines = BufReader::new(stderr).lines();
|
||||||
|
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
||||||
|
let mut file = File::options()
|
||||||
|
.create_new(true)
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(format!("{}.log", now.as_secs()))?;
|
||||||
|
|
||||||
|
let start = Instant::now();
|
||||||
|
while let Some(Ok(next)) = lines.next() {
|
||||||
|
let line = format!("{}~{next}\n", start.elapsed().as_millis());
|
||||||
|
file.write_all(line.as_bytes())?;
|
||||||
|
}
|
||||||
|
file.flush()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -24,9 +24,12 @@ pub fn style_bar<'s, const N: usize>(
|
|||||||
if remaining_width == 0 {
|
if remaining_width == 0 {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
let remaining_width = remaining_width.saturating_sub((INFO_WIDTH as u16 + 3) * 2);
|
||||||
|
|
||||||
let possible_chunks = remaining_width.saturating_div(INFO_WIDTH as u16 + 3);
|
let possible_chunks = remaining_width.saturating_div(INFO_WIDTH as u16 + 3);
|
||||||
let possible_chunks = possible_chunks.min(3);
|
let possible_chunks = possible_chunks.min(4);
|
||||||
let leftover_width = remaining_width.saturating_sub(possible_chunks * (INFO_WIDTH as u16 + 3));
|
let leftover_width = ((INFO_WIDTH as u16 + 3) * 2)
|
||||||
|
+ remaining_width.saturating_sub(possible_chunks * (INFO_WIDTH as u16 + 3));
|
||||||
let download_done_human = pad_string(
|
let download_done_human = pad_string(
|
||||||
DOWNLOAD_STYLE
|
DOWNLOAD_STYLE
|
||||||
.style(HumanBytes(download_done as u64).to_string())
|
.style(HumanBytes(download_done as u64).to_string())
|
||||||
@@ -44,7 +47,7 @@ pub fn style_bar<'s, const N: usize>(
|
|||||||
let bar = bar.scale(leftover_width as u64).to_string();
|
let bar = bar.scale(leftover_width as u64).to_string();
|
||||||
|
|
||||||
match possible_chunks {
|
match possible_chunks {
|
||||||
0 => format!("{status} | {download_done_human}"),
|
0 => format!("{status} | [{bar}]"),
|
||||||
1 => format!("{status} | {download_done_human} | [{bar}]"),
|
1 => format!("{status} | {download_done_human} | [{bar}]"),
|
||||||
2 => format!("{status} | {work_per_sec} | {download_done_human} | [{bar}]"),
|
2 => format!("{status} | {work_per_sec} | {download_done_human} | [{bar}]"),
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ impl Handler for GlobalHandler {
|
|||||||
action: &crate::action::Action,
|
action: &crate::action::Action,
|
||||||
) -> color_eyre::Result<bool> {
|
) -> color_eyre::Result<bool> {
|
||||||
match action {
|
match action {
|
||||||
|
Action::Msg { level, msg } => {
|
||||||
|
if *level > 4 {
|
||||||
|
state.println(format!("{level}: {msg}"))?;
|
||||||
|
}
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
Action::Start {
|
Action::Start {
|
||||||
start_type: StartFields::QueryPathInfo { path, source },
|
start_type: StartFields::QueryPathInfo { path, source },
|
||||||
id,
|
id,
|
||||||
|
|||||||
9
src/lib.rs
Normal file
9
src/lib.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
pub mod action;
|
||||||
|
pub mod action_raw;
|
||||||
|
pub mod download_display;
|
||||||
|
pub mod estimator;
|
||||||
|
pub mod handlers;
|
||||||
|
pub mod multibar;
|
||||||
|
pub mod nix_path;
|
||||||
|
pub mod state;
|
||||||
|
pub mod util;
|
||||||
34
src/main.rs
34
src/main.rs
@@ -1,34 +0,0 @@
|
|||||||
use std::sync::LazyLock;
|
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use console::Term;
|
|
||||||
use owo_colors::OwoColorize;
|
|
||||||
|
|
||||||
use crate::state::State;
|
|
||||||
|
|
||||||
pub mod action;
|
|
||||||
pub mod action_raw;
|
|
||||||
pub mod download_display;
|
|
||||||
pub mod estimator;
|
|
||||||
pub mod handlers;
|
|
||||||
pub mod multibar;
|
|
||||||
pub mod nix_path;
|
|
||||||
pub mod state;
|
|
||||||
pub mod util;
|
|
||||||
|
|
||||||
fn main() -> Result<(), color_eyre::Report> {
|
|
||||||
color_eyre::install().unwrap();
|
|
||||||
|
|
||||||
let lines = std::fs::read_to_string("build.log")?;
|
|
||||||
let mut state = State::new(Term::stderr().size().1);
|
|
||||||
|
|
||||||
for line in lines.lines() {
|
|
||||||
let line = line.strip_prefix("@nix ").unwrap_or(line);
|
|
||||||
sleep(Duration::from_millis(1));
|
|
||||||
let action = action::Action::parse(line)?;
|
|
||||||
state.handle(&action)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user