aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/repl_exec.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-19 22:48:23 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-19 22:48:23 +0800
commit39d66182f0290bacc10886c2659874bd9edc2d4b (patch)
tree7b0e9463575a8350cd5a61bd0d02c9bada892b7f /mingling_core/src/program/repl_exec.rs
parentbd4b09b06181093c95e865b04d4a9cdda7dd0728 (diff)
Add `empty_result!` macro and `REPL` resource, improve examples
Diffstat (limited to 'mingling_core/src/program/repl_exec.rs')
-rw-r--r--mingling_core/src/program/repl_exec.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/mingling_core/src/program/repl_exec.rs b/mingling_core/src/program/repl_exec.rs
index 5246ece..5417252 100644
--- a/mingling_core/src/program/repl_exec.rs
+++ b/mingling_core/src/program/repl_exec.rs
@@ -3,11 +3,15 @@
use std::io::Write;
+#[doc(hidden)]
+pub mod res;
+
mod splitter;
use crate::error::{ProgramInternalExecuteError, ProgramPanic};
use crate::program::repl_exec::splitter::split_input_string;
use crate::{Program, ProgramCollect, RenderResult};
+use crate::{program::repl_exec::res::REPL, this};
#[cfg(not(feature = "async"))]
impl<C> Program<C>
@@ -18,10 +22,13 @@ where
///
/// This method starts an infinite loop that continuously reads user input, parses commands, executes them,
/// and displays the execution result or error message. It is suitable for scenarios requiring command-line interaction with the user.
- pub fn exec_repl(self) {
+ pub fn exec_repl(mut self) {
+ // Inject default REPL resource
+ self.with_resource(REPL::default());
+
self.run_hook_repl_on_begin();
- self.exec_wrapper(|p| -> ! {
+ self.exec_wrapper(|p| -> () {
loop {
p.run_hook_repl_pre_readline();
let readline = readline_or_empty();
@@ -38,6 +45,10 @@ where
}
_ => {}
}
+
+ if this::<C>().res::<REPL>().unwrap().exit {
+ break;
+ }
}
});
}
@@ -56,9 +67,12 @@ where
/// **Note:** When the `async` feature is enabled, panic unwinding is not supported.
/// Any panics during command execution will result in an abort rather than being caught and handled gracefully.
pub async fn exec_repl(self) {
+ // Inject default REPL resource
+ self.with_resource(REPL::default());
+
self.run_hook_repl_on_begin();
- self.exec_wrapper(async |p| -> ! {
+ self.exec_wrapper(async |p| -> () {
loop {
p.run_hook_repl_pre_readline();
let readline = readline_or_empty();
@@ -72,6 +86,10 @@ where
}
_ => {}
}
+
+ if this::<C>().res::<REPL>().unwrap().exit {
+ break;
+ }
}
})
.await;