Skip to content

Commit

Permalink
pretty progress in a generalized form
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 1, 2020
1 parent 026a0dd commit caa883b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pretty-cli = ["structopt",
"prodash/log-renderer",
"prodash/tui-renderer",
"prodash/localtime",
"env_logger"]
"env_logger",
"smol"]
lean-cli = ["argh", "git-features/progress-log", "env_logger"]

[dependencies]
Expand All @@ -39,7 +40,8 @@ git-features = { version = "0.1.0", path = "git-features" }

structopt = { version = "0.3.14", optional = true }
argh = { version = "0.1.3", optional = true }
prodash = { version = "4.0.4", optional = true, default-features = false }
prodash = { version = "4.0.5", optional = true, default-features = false }
smol = { version = "0.1.18", optional = true }
env_logger = { version = "0.7.1", optional = true, default-features = false, features = ["humantime", "termcolor", "atty"] }

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion git-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ fastsha1 = { package = "sha-1", version = "0.9.1", optional = true }

# progress
log = { version = "0.4.8", optional = true }
prodash = { version = "4.0.4", optional = true, default-features = false }
prodash = { version = "4.0.5", optional = true, default-features = false }
48 changes: 37 additions & 11 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,58 @@ mod options {
/// if set, verbose progress messages are printed line by line
#[structopt(long, short = "v")]
verbose: bool,

/// if set, bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
progress: bool,

/// The '.pack' or '.idx' file whose checksum to validate.
#[structopt(parse(from_os_str))]
path: PathBuf,
},
}
}

fn init_progress(name: &str, verbose: bool) -> progress::DoOrDiscard<progress::Log> {
fn init_progress(
name: &str,
verbose: bool,
progress: bool,
) -> Option<progress::Either<progress::Log, prodash::tree::Item>> {
super::init_env_logger(verbose);
progress::DoOrDiscard::from(if verbose {
Some(progress::Log::new(name))
} else {
None
})
match (verbose, progress) {
(false, false) => None,
(true, false) => Some(progress::Either::Left(progress::Log::new(name))),
(true, true) | (false, true) => {
let progress = prodash::Tree::new();
let sub_progress = progress.add_child(name);
let render_tui = prodash::tui::render(
progress,
prodash::tui::TuiOptions {
title: "gitoxide".into(),
frames_per_second: 6.0,
..Default::default()
},
)
.expect("tui to come up without io error");
std::thread::spawn(move || smol::run(render_tui));

Some(progress::Either::Right(sub_progress))
}
}
}

pub fn main() -> Result<()> {
use options::*;
let args = Args::from_args();
match args.cmd {
Subcommands::VerifyPack { path, verbose } => core::verify_pack_or_pack_index(
Subcommands::VerifyPack {
path,
init_progress("verify-pack", verbose).into(),
stdout(),
stderr(),
),
verbose,
progress,
} => {
let progress = init_progress("verify-pack", verbose, progress);
core::verify_pack_or_pack_index(path, progress, stdout(), stderr())
}
}?;
Ok(())
}
4 changes: 1 addition & 3 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
* [x] validate index and pack
* **progress**
* [x] for `lean` binary behind --verbose flag
* [ ] for `pretty` binary with support for
* [x] logging
* [ ] TUI
* [x] for `pretty` binary with support for logging and TUI
* [ ] statistics
* [ ] a verbose mode to list each object in a pack, similar to existing git-verify-pack
* **stress**
Expand Down

0 comments on commit caa883b

Please sign in to comment.