From 5d61201e9532cfc92f4b93e34b7c10a97cfb35df Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 18 May 2026 22:32:05 +0800 Subject: Add REPL pre/post readline hooks and suppress dead code warnings --- mingling_core/src/program/repl_exec.rs | 46 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'mingling_core/src/program/repl_exec.rs') diff --git a/mingling_core/src/program/repl_exec.rs b/mingling_core/src/program/repl_exec.rs index c182f78..f3dd9f7 100644 --- a/mingling_core/src/program/repl_exec.rs +++ b/mingling_core/src/program/repl_exec.rs @@ -1,3 +1,6 @@ +#![allow(unused_imports)] +#![allow(dead_code)] + use std::io::Write; mod splitter; @@ -11,37 +14,28 @@ impl Program where C: ProgramCollect + Send + Sync + 'static, { + /// Executes the REPL interactive CLI mode. + /// + /// 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. + /// + /// # Important + /// + /// **REPL mode is currently only available when the `async` feature is disabled; it does not support async.** + /// + /// If the `async` feature is enabled, this method will be unavailable (as it is protected by `#[cfg(not(feature = "async"))]` conditional compilation). + /// Future versions may support asynchronous REPL, but currently only synchronous mode is supported. pub fn exec_repl(self) { self.run_hook_repl_on_begin(); self.exec_wrapper(|p| -> ! { loop { - let args = split_input_string(readline_or_empty()); - match exec_once(p, args) { - Ok(r) => { - p.run_hook_repl_on_receive_result(&r); - } - Err(ProgramInternalExecuteError::REPLPanic(panic)) => { - p.run_hook_repl_on_panic(&panic); - } - _ => {} - } - } - }); - } -} + p.run_hook_repl_pre_readline(); + let readline = readline_or_empty(); + p.run_hook_repl_post_readline(&readline); -#[cfg(feature = "async")] -impl Program -where - C: ProgramCollect + Send + Sync, -{ - pub async fn exec_repl(self) { - self.run_hook_repl_on_begin(); + let args = split_input_string(readline.clone()); - self.exec_wrapper(|p| -> ! { - loop { - let args = split_input_string(readline_or_empty()); match exec_once(p, args) { Ok(r) => { p.run_hook_repl_on_receive_result(&r); @@ -52,8 +46,7 @@ where _ => {} } } - }) - .await; + }); } } @@ -68,6 +61,7 @@ fn readline_or_empty() -> String { readline().unwrap_or("".to_string()) } +#[cfg(not(feature = "async"))] fn exec_once( p: &'static Program, args: Vec, -- cgit