aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/repl_exec.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-21 15:12:58 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-21 15:21:37 +0800
commit74b5a80475e2230c0a494beac5ec86a985c2974f (patch)
tree18892e7b6c0a0c6b4a3ac65fb497d7a55d5ae16f /mingling_core/src/program/repl_exec.rs
parent4704f6d54108bcc8f9b2fb7f4b3c4e224b4a7809 (diff)
Refactor REPL hooks into modular setups and add new hook types
Diffstat (limited to 'mingling_core/src/program/repl_exec.rs')
-rw-r--r--mingling_core/src/program/repl_exec.rs25
1 files changed, 12 insertions, 13 deletions
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::<C>().res::<REPL>().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::<C>().res::<REPL>().unwrap().exit {
+ p.run_hook_repl_exit();
break;
}
+
+ p.run_hook_repl_loop_once();
}
})
.await;
}
}
-fn readline() -> Result<String, std::io::Error> {
- 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<C>(
p: &'static Program<C>,