mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
vanityaddr: Remove indicatif dependency.
This commit is contained in:
187
Cargo.lock
generated
187
Cargo.lock
generated
@@ -852,12 +852,6 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cassowary"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.79"
|
version = "1.0.79"
|
||||||
@@ -1092,19 +1086,6 @@ dependencies = [
|
|||||||
"toml 0.5.11",
|
"toml 0.5.11",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "console"
|
|
||||||
version = "0.15.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
|
|
||||||
dependencies = [
|
|
||||||
"encode_unicode 0.3.6",
|
|
||||||
"lazy_static",
|
|
||||||
"libc",
|
|
||||||
"unicode-width",
|
|
||||||
"windows-sys 0.45.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "const-cstr"
|
name = "const-cstr"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -1399,31 +1380,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossterm"
|
|
||||||
version = "0.25.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"crossterm_winapi",
|
|
||||||
"libc",
|
|
||||||
"mio",
|
|
||||||
"parking_lot 0.12.1",
|
|
||||||
"signal-hook",
|
|
||||||
"signal-hook-mio",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossterm_winapi"
|
|
||||||
version = "0.9.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchy"
|
name = "crunchy"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@@ -1579,7 +1535,6 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"halo2_gadgets",
|
"halo2_gadgets",
|
||||||
"halo2_proofs",
|
"halo2_proofs",
|
||||||
"indicatif",
|
|
||||||
"itertools 0.10.5",
|
"itertools 0.10.5",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -2294,29 +2249,6 @@ dependencies = [
|
|||||||
"libloading 0.8.0",
|
"libloading 0.8.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dnetview"
|
|
||||||
version = "0.4.1"
|
|
||||||
dependencies = [
|
|
||||||
"async-channel",
|
|
||||||
"async-std",
|
|
||||||
"clap 4.3.10",
|
|
||||||
"darkfi",
|
|
||||||
"easy-parallel",
|
|
||||||
"hex",
|
|
||||||
"libsqlite3-sys",
|
|
||||||
"log",
|
|
||||||
"rand 0.8.5",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"simplelog",
|
|
||||||
"smol",
|
|
||||||
"termion 2.0.1",
|
|
||||||
"thiserror",
|
|
||||||
"tui",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "downcast-rs"
|
name = "downcast-rs"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -2482,12 +2414,6 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "encode_unicode"
|
|
||||||
version = "0.3.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encode_unicode"
|
name = "encode_unicode"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@@ -3352,19 +3278,6 @@ dependencies = [
|
|||||||
"hashbrown 0.14.0",
|
"hashbrown 0.14.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indicatif"
|
|
||||||
version = "0.17.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8ff8cc23a7393a397ed1d7f56e6365cba772aba9f9912ab968b03043c395d057"
|
|
||||||
dependencies = [
|
|
||||||
"console",
|
|
||||||
"instant",
|
|
||||||
"number_prefix",
|
|
||||||
"portable-atomic",
|
|
||||||
"unicode-width",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indoc"
|
name = "indoc"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
@@ -3755,18 +3668,6 @@ dependencies = [
|
|||||||
"simd-adler32",
|
"simd-adler32",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mio"
|
|
||||||
version = "0.8.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
|
||||||
"windows-sys 0.48.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "more-asserts"
|
name = "more-asserts"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@@ -3997,18 +3898,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "number_prefix"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "numtoa"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.31.1"
|
version = "0.31.1"
|
||||||
@@ -4486,12 +4375,6 @@ dependencies = [
|
|||||||
"universal-hash",
|
"universal-hash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "portable-atomic"
|
|
||||||
version = "1.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "767eb9f07d4a5ebcb39bbf2d452058a93c011373abf6832e24194a1c3f004794"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "postage"
|
name = "postage"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -4520,7 +4403,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a"
|
checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"csv",
|
"csv",
|
||||||
"encode_unicode 1.0.0",
|
"encode_unicode",
|
||||||
"is-terminal",
|
"is-terminal",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"term",
|
"term",
|
||||||
@@ -4840,15 +4723,6 @@ dependencies = [
|
|||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "redox_termios"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
|
||||||
dependencies = [
|
|
||||||
"redox_syscall 0.2.16",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_users"
|
name = "redox_users"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
@@ -5455,17 +5329,6 @@ dependencies = [
|
|||||||
"signal-hook",
|
"signal-hook",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "signal-hook-mio"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"mio",
|
|
||||||
"signal-hook",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.1"
|
version = "1.4.1"
|
||||||
@@ -5976,30 +5839,6 @@ dependencies = [
|
|||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termion"
|
|
||||||
version = "1.5.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"numtoa",
|
|
||||||
"redox_syscall 0.2.16",
|
|
||||||
"redox_termios",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termion"
|
|
||||||
version = "2.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"numtoa",
|
|
||||||
"redox_syscall 0.2.16",
|
|
||||||
"redox_termios",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -6869,20 +6708,6 @@ version = "0.17.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff"
|
checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tui"
|
|
||||||
version = "0.19.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"cassowary",
|
|
||||||
"crossterm",
|
|
||||||
"termion 1.5.6",
|
|
||||||
"unicode-segmentation",
|
|
||||||
"unicode-width",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typed-index-collections"
|
name = "typed-index-collections"
|
||||||
version = "3.1.0"
|
version = "3.1.0"
|
||||||
@@ -7048,7 +6873,6 @@ dependencies = [
|
|||||||
"ctrlc",
|
"ctrlc",
|
||||||
"darkfi",
|
"darkfi",
|
||||||
"darkfi-sdk",
|
"darkfi-sdk",
|
||||||
"indicatif",
|
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"rayon",
|
"rayon",
|
||||||
]
|
]
|
||||||
@@ -7499,15 +7323,6 @@ dependencies = [
|
|||||||
"windows_x86_64_msvc 0.33.0",
|
"windows_x86_64_msvc 0.33.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.45.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
|
||||||
dependencies = [
|
|
||||||
"windows-targets 0.42.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ url = {version = "2.4.0", features = ["serde"], optional = true}
|
|||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
# TODO: Implement something simple and kill these deps
|
# TODO: Implement something simple and kill these deps
|
||||||
indicatif = {version = "0.17.5", optional = true}
|
|
||||||
simplelog = {version = "0.12.1", optional = true}
|
simplelog = {version = "0.12.1", optional = true}
|
||||||
|
|
||||||
# Crypto
|
# Crypto
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ edition = "2021"
|
|||||||
bs58 = "0.5.0"
|
bs58 = "0.5.0"
|
||||||
clap = {version = "4.3.3", features = ["derive"]}
|
clap = {version = "4.3.3", features = ["derive"]}
|
||||||
ctrlc = "3.4.0"
|
ctrlc = "3.4.0"
|
||||||
darkfi = {path = "../../"}
|
darkfi = {path = "../../", features = ["util"]}
|
||||||
darkfi-sdk = {path = "../../src/sdk"}
|
darkfi-sdk = {path = "../../src/sdk"}
|
||||||
indicatif = "0.17.5"
|
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rayon = "1.7.0"
|
rayon = "1.7.0"
|
||||||
|
|||||||
@@ -16,11 +16,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{process::exit, sync::mpsc::channel};
|
use std::{
|
||||||
|
process::exit,
|
||||||
|
sync::{mpsc::channel, Arc},
|
||||||
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use darkfi::util::cli::ProgressInc;
|
||||||
use darkfi_sdk::crypto::{ContractId, PublicKey, SecretKey, TokenId};
|
use darkfi_sdk::crypto::{ContractId, PublicKey, SecretKey, TokenId};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
@@ -175,16 +178,20 @@ fn main() {
|
|||||||
.expect("Error setting SIGINT handler");
|
.expect("Error setting SIGINT handler");
|
||||||
|
|
||||||
// Something fancy
|
// Something fancy
|
||||||
|
let progress = Arc::new(ProgressInc::new());
|
||||||
|
/*
|
||||||
let progress = ProgressBar::new_spinner();
|
let progress = ProgressBar::new_spinner();
|
||||||
let template =
|
let template =
|
||||||
ProgressStyle::default_bar().template("[{elapsed_precise}] {pos} attempts").unwrap();
|
ProgressStyle::default_bar().template("[{elapsed_precise}] {pos} attempts").unwrap();
|
||||||
progress.set_style(template);
|
progress.set_style(template);
|
||||||
|
*/
|
||||||
|
|
||||||
// Fire off the threadpool
|
// Fire off the threadpool
|
||||||
|
let progress_ = progress.clone();
|
||||||
rayon_pool.spawn(move || {
|
rayon_pool.spawn(move || {
|
||||||
if args.token_id {
|
if args.token_id {
|
||||||
let tid = rayon::iter::repeat(DrkToken::new)
|
let tid = rayon::iter::repeat(DrkToken::new)
|
||||||
.inspect(|_| progress.inc(1))
|
.inspect(|_| progress_.inc(1))
|
||||||
.map(|create| create())
|
.map(|create| create())
|
||||||
.find_any(|token_id| token_id.starts_with_any(&args.prefix, args.case_sensitive))
|
.find_any(|token_id| token_id.starts_with_any(&args.prefix, args.case_sensitive))
|
||||||
.expect("Failed to find a token ID match");
|
.expect("Failed to find a token ID match");
|
||||||
@@ -192,8 +199,8 @@ fn main() {
|
|||||||
// The above will keep running until it finds a match or until the
|
// The above will keep running until it finds a match or until the
|
||||||
// program terminates. Only if a match is found shall the following
|
// program terminates. Only if a match is found shall the following
|
||||||
// code be executed and the program exit successfully:
|
// code be executed and the program exit successfully:
|
||||||
let attempts = progress.position();
|
let attempts = progress_.position();
|
||||||
progress.finish_and_clear();
|
progress_.finish_and_clear();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{{\"token_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
|
"{{\"token_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
|
||||||
@@ -201,13 +208,13 @@ fn main() {
|
|||||||
);
|
);
|
||||||
} else if args.address {
|
} else if args.address {
|
||||||
let addr = rayon::iter::repeat(DrkAddr::new)
|
let addr = rayon::iter::repeat(DrkAddr::new)
|
||||||
.inspect(|_| progress.inc(1))
|
.inspect(|_| progress_.inc(1))
|
||||||
.map(|create| create())
|
.map(|create| create())
|
||||||
.find_any(|address| address.starts_with_any(&args.prefix, args.case_sensitive))
|
.find_any(|address| address.starts_with_any(&args.prefix, args.case_sensitive))
|
||||||
.expect("Failed to find an address match");
|
.expect("Failed to find an address match");
|
||||||
|
|
||||||
let attempts = progress.position();
|
let attempts = progress_.position();
|
||||||
progress.finish_and_clear();
|
progress_.finish_and_clear();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{{\"address\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
|
"{{\"address\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
|
||||||
@@ -215,15 +222,15 @@ fn main() {
|
|||||||
);
|
);
|
||||||
} else if args.contract_id {
|
} else if args.contract_id {
|
||||||
let cid = rayon::iter::repeat(DrkContract::new)
|
let cid = rayon::iter::repeat(DrkContract::new)
|
||||||
.inspect(|_| progress.inc(1))
|
.inspect(|_| progress_.inc(1))
|
||||||
.map(|create| create())
|
.map(|create| create())
|
||||||
.find_any(|contract_id| {
|
.find_any(|contract_id| {
|
||||||
contract_id.starts_with_any(&args.prefix, args.case_sensitive)
|
contract_id.starts_with_any(&args.prefix, args.case_sensitive)
|
||||||
})
|
})
|
||||||
.expect("Failed to find a contract ID match");
|
.expect("Failed to find a contract ID match");
|
||||||
|
|
||||||
let attempts = progress.position();
|
let attempts = progress_.position();
|
||||||
progress.finish_and_clear();
|
progress_.finish_and_clear();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{{\"contract_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
|
"{{\"contract_id\":\"{}\",\"attempts\":{},\"secret\":\"{}\"}}",
|
||||||
@@ -236,6 +243,7 @@ fn main() {
|
|||||||
|
|
||||||
// This now blocks and lets our threadpool execute in the background.
|
// This now blocks and lets our threadpool execute in the background.
|
||||||
rx.recv().expect("Could not receive from channel");
|
rx.recv().expect("Could not receive from channel");
|
||||||
eprintln!("\rCaught SIGINT, exiting...");
|
progress.finish_and_clear();
|
||||||
|
eprintln!("\r\x1b[2KCaught SIGINT, exiting...");
|
||||||
exit(127);
|
exit(127);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ use std::{
|
|||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
str,
|
str,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
@@ -305,3 +307,43 @@ pub fn fg_green(message: &str) -> String {
|
|||||||
pub fn fg_reset() -> String {
|
pub fn fg_reset() -> String {
|
||||||
"\x1b[0m".to_string()
|
"\x1b[0m".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ProgressInc {
|
||||||
|
position: Arc<Mutex<u64>>,
|
||||||
|
timer: Arc<Mutex<Option<Instant>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProgressInc {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
eprint!("\x1b[?25l");
|
||||||
|
Self { position: Arc::new(Mutex::new(0)), timer: Arc::new(Mutex::new(None)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn inc(&self, n: u64) {
|
||||||
|
let mut position = self.position.lock().unwrap();
|
||||||
|
|
||||||
|
if *position == 0 {
|
||||||
|
*self.timer.lock().unwrap() = Some(Instant::now());
|
||||||
|
}
|
||||||
|
|
||||||
|
*position += n;
|
||||||
|
|
||||||
|
let binding = self.timer.lock().unwrap();
|
||||||
|
let Some(elapsed) = binding.as_ref() else {
|
||||||
|
return
|
||||||
|
};
|
||||||
|
let elapsed = elapsed.elapsed();
|
||||||
|
let pos = *position;
|
||||||
|
|
||||||
|
eprint!("\r[{elapsed:?}] {pos} attempts");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn position(&self) -> u64 {
|
||||||
|
*self.position.lock().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn finish_and_clear(&self) {
|
||||||
|
*self.timer.lock().unwrap() = None;
|
||||||
|
eprint!("\r\x1b[2K\x1b[?25h");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user