From 20dd9f182ec842a267fc48c72578c6169c121ccb Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 15 Aug 2026 20:21:45 +0800 Subject: refactor: rename Confirmer to ResConfirm and OSC94 to ResOSC94 Rename `Confirmer` resource to `ResConfirm`, `ConfirmerCount` to `ConfirmCount`, and `ConfirmerPredicate` to `ConfirmPredicate`. Update related setups, guards, and documentation references. --- mingling/src/setups/confirm.rs | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 mingling/src/setups/confirm.rs (limited to 'mingling/src/setups/confirm.rs') diff --git a/mingling/src/setups/confirm.rs b/mingling/src/setups/confirm.rs new file mode 100644 index 0000000..6635420 --- /dev/null +++ b/mingling/src/setups/confirm.rs @@ -0,0 +1,60 @@ +use mingling_core::{ + Program, ProgramCollect, config, hook::ProgramHook, setup::ProgramSetup, this, +}; + +use crate::res::ResConfirm; + +/// Confirm setup for managing confirmation state +/// +/// This Setup manages the confirmation flag within the program's resource +/// store. It registers a [`ResConfirm`] resource and sets up a hook that +/// checks the user's confirmation mode during program execution. +/// +/// # Usage +/// +/// This Setup can be registered using the +/// [`Program`](https://docs.rs/mingling/latest/mingling/struct.Program.html) +/// `with_setup` method, for example: +/// +/// ```rust +/// # use mingling::MockProgramCollect as ThisProgram; +/// use mingling::Program; +/// use mingling::setup::ConfirmSetup; +/// +/// let mut program = Program::::new(); +/// program.with_setup(ConfirmSetup); +/// ``` +/// +/// # Behavior +/// +/// - Registers a [`ResConfirm`] resource that tracks confirmation state. +/// - At the beginning of command execution, checks whether the user's +/// confirmation mode is set to `Skip`. +/// - If confirmation is skipped, the [`Confirm`] resource is updated +/// to record the confirmed state. +/// +/// # Notes +/// +/// - This Setup applies uniformly to all subcommands of the entire program. +/// - The confirmation state is determined by the global `config` setting; +/// it does not support per-command overrides. +pub struct ConfirmSetup; + +impl ProgramSetup for ConfirmSetup +where + C: ProgramCollect + 'static, +{ + fn setup(self, program: &mut Program) { + program.with_resource(ResConfirm::new()); + + program.with_hook(ProgramHook::empty().on_pre_dispatch::<_, ()>(|_| { + let p = this::(); + let confirmed = p.user_context.confirmation == config::ConfirmationMode::Skip; + if confirmed { + p.modify_res(|c: &mut ResConfirm| { + c.set_confirmed(); + }); + } + })); + } +} -- cgit