Create `pijul-interaction` crate

finchie
Jul 13, 2023, 10:28 AM
ABPFWGKH24JK7TLAGDVENTA5VSVRANPBVRD555WCQMNW56BL7SZQC

Dependencies

  • [2] DVBSW7SI Bump dependencies with minor-level changes
  • [3] JMOHVR5E Bump edition to 2021
  • [4] TNN56XYK libpijul alpha.43
  • [5] EJ7TFFOW Re-adding Cargo.lock
  • [6] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [7] RDQYEED2 Fixing versions
  • [8] SGXOEWHU Adding a patched chardetng (temporarily)
  • [9] SYP2J7VC Removing the progressbar member from the workspace
  • [10] BNPSVXIC Friendlier progress bars
  • [*] STG7MO5M Version bump
  • [*] ENWJBQGQ Fixing a deprecation warning in ed25519_dalek.

Change contents

  • edit in Cargo.lock at line 126
    [12.542]
    [4.1890]
    dependencies = [
    "backtrace",
    ]
  • edit in Cargo.lock at line 1479
    [2.4671]
    [4.32475]
    ]
    [[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-segmentation",
    "unicode-width",
  • edit in Cargo.lock at line 1974
    [4.43389]
    [4.43389]
    [[package]]
    name = "number_prefix"
    version = "0.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
  • edit in Cargo.lock at line 2207
    [4.48476]
    [4.48476]
    "pijul-interaction",
  • edit in Cargo.lock at line 2219
    [4.48617][4.48617:48635]()
    "terminal_size",
  • edit in Cargo.lock at line 2228
    [4.48756]
    [4.48756]
    ]
    [[package]]
    name = "pijul-interaction"
    version = "0.0.1"
    dependencies = [
    "anyhow",
    "indicatif",
    "lazy_static 1.4.0",
  • edit in Cargo.lock at line 2282
    [4.49790]
    [4.49790]
    [[package]]
    name = "portable-atomic"
    version = "1.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d220334a184db82b31b83f5ff093e3315280fb2b6bbc032022b2304a509aab7a"
  • edit in Cargo.lock at line 2923
    [4.64116][4.64116:64131](),[4.64131][4.64131:64353]()
    ]
    [[package]]
    name = "terminal_size"
    version = "0.1.17"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
    dependencies = [
    "libc",
    "winapi",
  • edit in Cargo.lock at line 3289
    [4.72360]
    [4.72360]
    name = "unicode-segmentation"
    version = "1.10.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
    [[package]]
  • replacement in Cargo.toml at line 2
    [4.1030201][4.230:280]()
    members = [ "pijul-macros", "pijul", "libpijul" ]
    [4.1030201]
    [3.72]
    members = [ "pijul-macros", "pijul", "libpijul", "pijul-interaction" ]
  • file addition: pijul-interaction (d--r------)
    [13.2]
  • file addition: src (d--r------)
    [0.1206]
  • file addition: progress.rs (----------)
    [0.1223]
    use std::time::Duration;
    use indicatif::MultiProgress;
    use lazy_static::lazy_static;
    use indicatif::ProgressStyle;
    lazy_static! {
    static ref MULTI_PROGRESS: MultiProgress = MultiProgress::new();
    }
    pub const DOWNLOAD_MESSAGE: &str = "Downloading changes";
    pub const APPLY_MESSAGE: &str = "Applying changes";
    pub const UPLOAD_MESSAGE: &str = "Uploading changes";
    pub const COMPLETE_MESSAGE: &str = "Completing changes";
    pub const OUTPUT_MESSAGE: &str = "Outputting repository";
    #[derive(Clone, Debug)]
    pub struct ProgressBar(Option<indicatif::ProgressBar>);
    impl Drop for ProgressBar {
    fn drop(&mut self) {
    // Make sure the progress bar doesn't disappear after completion
    if let Some(progress_bar) = &self.0 {
    progress_bar.finish();
    }
    }
    }
    impl ProgressBar {
    pub fn new(len: u64, message: &str) -> Result<Self, anyhow::Error> {
    let style =
    ProgressStyle::with_template("{msg:<20} [{bar:50}] {pos}/{len} [{elapsed_precise}]")?
    .progress_chars("=> ");
    let progress_bar = indicatif::ProgressBar::new(len)
    .with_style(style)
    .with_message(message.to_owned());
    MULTI_PROGRESS.add(progress_bar.clone());
    progress_bar.enable_steady_tick(Duration::from_millis(15));
    Ok(Self(Some(progress_bar)))
    }
    pub fn hidden() -> Self {
    Self(None)
    }
    pub fn inc(&self, delta: u64) {
    if let Some(progress) = self.0.clone() {
    progress.inc(delta);
    }
    }
    pub fn inner(&self) -> Option<indicatif::ProgressBar> {
    self.0.clone()
    }
    }
    #[derive(Clone, Debug)]
    pub struct Spinner(indicatif::ProgressBar);
    impl Drop for Spinner {
    fn drop(&mut self) {
    // Make sure the spinner doesn't disappear after completion
    self.finish().unwrap();
    }
    }
    impl Spinner {
    pub fn new(message: &str) -> Result<Self, anyhow::Error> {
    let style = ProgressStyle::with_template("{msg}{spinner}")?
    .tick_strings(&[". ", ".. ", "...", " "]);
    let spinner = indicatif::ProgressBar::new_spinner()
    .with_style(style)
    .with_message(message.to_owned());
    spinner.enable_steady_tick(Duration::from_millis(200));
    MULTI_PROGRESS.add(spinner.clone());
    Ok(Self(spinner))
    }
    pub fn finish(&self) -> Result<(), anyhow::Error> {
    self.0.set_style(ProgressStyle::with_template("{msg}")?);
    self.0
    .finish_with_message(format!("{}... done!", self.0.message()));
    Ok(())
    }
    }
  • file addition: lib.rs (----------)
    [0.1223]
    pub mod progress;
  • file addition: Cargo.toml (----------)
    [0.1206]
    [package]
    name = "pijul-interaction"
    description = "Human friendly input/output (progress bars, passwords etc) for contexts such as terminals or GUIs"
    version = "0.0.1"
    authors = ["Finchie"]
    edition = "2021"
    repository = "https://nest.pijul.com/pijul/pijul"
    license = "GPL-2.0"
    include = [ "Cargo.toml", "src" ]
    [dependencies]
    anyhow = { version = "1.0", features = ["backtrace"] }
    indicatif = { version = "0.17", features = ["improved_unicode"] }
    lazy_static = "1.4"