From 88c3f15b3f48c2dd56f2c5498df5b5eed8f718f9 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 10 Jun 2022 13:45:20 +1000 Subject: [PATCH] Rename `Confirmer` to `UIThread` Signed-off-by: Jiahao XU --- src/helpers.rs | 4 ++-- src/helpers/{confirm.rs => ui_thread.rs} | 10 +++++----- src/main.rs | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) rename src/helpers/{confirm.rs => ui_thread.rs} (94%) diff --git a/src/helpers.rs b/src/helpers.rs index 0266b89a..5ae86896 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -19,8 +19,8 @@ pub use async_extracter::extract_archive_stream; mod auto_abort_join_handle; pub use auto_abort_join_handle::AutoAbortJoinHandle; -mod confirm; -pub use confirm::Confirmer; +mod ui_thread; +pub use ui_thread::UIThread; mod extracter; mod readable_rx; diff --git a/src/helpers/confirm.rs b/src/helpers/ui_thread.rs similarity index 94% rename from src/helpers/confirm.rs rename to src/helpers/ui_thread.rs index 088a2aa7..8daf945c 100644 --- a/src/helpers/confirm.rs +++ b/src/helpers/ui_thread.rs @@ -6,7 +6,7 @@ use tokio::task::spawn_blocking; use crate::BinstallError; #[derive(Debug)] -struct ConfirmerInner { +struct UIThreadInner { /// Request for confirmation request_tx: mpsc::Sender<()>, @@ -14,7 +14,7 @@ struct ConfirmerInner { confirm_rx: mpsc::Receiver>, } -impl ConfirmerInner { +impl UIThreadInner { fn new() -> Self { let (request_tx, mut request_rx) = mpsc::channel(1); let (confirm_tx, confirm_rx) = mpsc::channel(10); @@ -75,13 +75,13 @@ impl ConfirmerInner { } #[derive(Debug)] -pub struct Confirmer(Option); +pub struct UIThread(Option); -impl Confirmer { +impl UIThread { /// * `enable` - `true` to enable confirmation, `false` to disable it. pub fn new(enable: bool) -> Self { Self(if enable { - Some(ConfirmerInner::new()) + Some(UIThreadInner::new()) } else { None }) diff --git a/src/main.rs b/src/main.rs index 62d71439..5b89353c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -191,7 +191,7 @@ async fn entry() -> Result<()> { ) .unwrap(); - let mut confirmer = Confirmer::new(!opts.no_confirm); + let mut uithread = UIThread::new(!opts.no_confirm); // Compute install directory let install_path = get_install_path(opts.install_path.as_deref()).ok_or_else(|| { @@ -231,7 +231,7 @@ async fn entry() -> Result<()> { ); if !opts.dry_run { - confirmer.confirm().await?; + uithread.confirm().await?; } } @@ -305,7 +305,7 @@ async fn entry() -> Result<()> { opts, package, temp_dir, - &mut confirmer, + &mut uithread, ) .await } @@ -320,7 +320,7 @@ async fn entry() -> Result<()> { .first() .ok_or_else(|| miette!("No viable targets found, try with `--targets`"))?; - install_from_source(opts, package, target, &mut confirmer).await + install_from_source(opts, package, target, &mut uithread).await } } } @@ -334,7 +334,7 @@ async fn install_from_package( opts: Options, package: Package, temp_dir: TempDir, - confirmer: &mut Confirmer, + uithread: &mut UIThread, ) -> Result<()> { // Prompt user for third-party source if fetcher.is_third_party() { @@ -343,7 +343,7 @@ async fn install_from_package( fetcher.source_name() ); if !opts.dry_run { - confirmer.confirm().await?; + uithread.confirm().await?; } } else { info!( @@ -433,7 +433,7 @@ async fn install_from_package( return Ok(()); } - confirmer.confirm().await?; + uithread.confirm().await?; info!("Installing binaries..."); for file in &bin_files { @@ -462,12 +462,12 @@ async fn install_from_source( opts: Options, package: Package, target: &str, - confirmer: &mut Confirmer, + uithread: &mut UIThread, ) -> Result<()> { // Prompt user for source install warn!("The package will be installed from source (with cargo)",); if !opts.dry_run { - confirmer.confirm().await?; + uithread.confirm().await?; } if opts.dry_run {