From 74b5a80475e2230c0a494beac5ec86a985c2974f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 21 May 2026 15:12:58 +0800 Subject: Refactor REPL hooks into modular setups and add new hook types --- mingling_core/src/program/repl_exec.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 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 5417252..c4232ab 100644 --- a/mingling_core/src/program/repl_exec.rs +++ b/mingling_core/src/program/repl_exec.rs @@ -31,11 +31,12 @@ where self.exec_wrapper(|p| -> () { loop { p.run_hook_repl_pre_readline(); - let readline = readline_or_empty(); + let readline = p.run_hook_repl_readline().unwrap_or_default(); p.run_hook_repl_post_readline(&readline); let args = split_input_string(readline.clone()); + p.run_hook_repl_pre_exec(&args); match exec_once(p, args) { Ok(r) => { p.run_hook_repl_on_receive_result(&r); @@ -45,10 +46,14 @@ where } _ => {} } + p.run_hook_repl_post_exec(); if this::().res::().unwrap().exit { + p.run_hook_repl_exit(); break; } + + p.run_hook_repl_loop_once(); } }); } @@ -75,38 +80,32 @@ where self.exec_wrapper(async |p| -> () { loop { p.run_hook_repl_pre_readline(); - let readline = readline_or_empty(); + let readline = p.run_hook_repl_readline().unwrap_or_default(); p.run_hook_repl_post_readline(&readline); let args = split_input_string(readline.clone()); + p.run_hook_repl_pre_exec(&args); match exec_once(p, args).await { Ok(r) => { p.run_hook_repl_on_receive_result(&r); } _ => {} } + p.run_hook_repl_post_exec(); if this::().res::().unwrap().exit { + p.run_hook_repl_exit(); break; } + + p.run_hook_repl_loop_once(); } }) .await; } } -fn readline() -> Result { - let mut input = String::new(); - std::io::stdout().flush()?; - std::io::stdin().read_line(&mut input)?; - Ok(input.trim().to_string()) -} - -fn readline_or_empty() -> String { - readline().unwrap_or("".to_string()) -} - #[cfg(not(feature = "async"))] fn exec_once( p: &'static Program, -- cgit