aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/confirm/count.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-15 19:51:27 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-15 19:51:27 +0800
commit046ac064b6f4790f9053ad1e6109843bb38f89dd (patch)
tree80c16af0d217f69001b3fad7a02dea49c2a3aebc /mingling/src/confirm/count.rs
parentaa2b0daa88089df32b3ea67d7c1831b5d8fd64f8 (diff)
feat: move OSC94 under its own module and add confirmer predicates
Extract OSC94 state and guard types from `res` into a dedicated `osc94` module, and add `ConfirmerCount` and `ConfirmerPredicate` types with `YesConfirm` and `TrueConfirm` implementations.
Diffstat (limited to 'mingling/src/confirm/count.rs')
-rw-r--r--mingling/src/confirm/count.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/mingling/src/confirm/count.rs b/mingling/src/confirm/count.rs
new file mode 100644
index 0000000..b9753c2
--- /dev/null
+++ b/mingling/src/confirm/count.rs
@@ -0,0 +1,31 @@
+/// Specifies the maximum number of attempts for a confirmation prompt.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ConfirmerCount {
+ /// Loop indefinitely until the user gives a parseable answer.
+ Loop,
+ /// Ask at most the specified number of times.
+ Max(usize),
+}
+
+macro_rules! impl_from_for_confirmer_count {
+ ($($t:ty),*) => {
+ $(
+ impl From<$t> for ConfirmerCount {
+ fn from(n: $t) -> Self {
+ if n == 0 {
+ ConfirmerCount::Loop
+ } else {
+ match usize::try_from(n) {
+ Ok(max) => ConfirmerCount::Max(max),
+ Err(_) => ConfirmerCount::Max(usize::MAX),
+ }
+ }
+ }
+ }
+ )*
+ };
+}
+
+impl_from_for_confirmer_count!(
+ i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize
+);