From 66fd547c0fac30d98565a92d93824237a4813669 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 26 Oct 2023 19:19:22 +0800 Subject: refactor: improve code quanity remove tokio::runtime::Runtime from client --- src/repl/handler.rs | 13 ++++--------- src/repl/mod.rs | 5 ++--- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'src/repl') diff --git a/src/repl/handler.rs b/src/repl/handler.rs index 53cdd98..e512cb5 100644 --- a/src/repl/handler.rs +++ b/src/repl/handler.rs @@ -1,4 +1,4 @@ -use crate::client::Client; +use crate::client::init_client; use crate::config::SharedConfig; use crate::print_now; use crate::render::render_stream; @@ -26,7 +26,6 @@ pub enum ReplCmd { #[allow(clippy::module_name_repetitions)] pub struct ReplCmdHandler { - client: Box, config: SharedConfig, reply: RefCell, abort: SharedAbortSignal, @@ -34,14 +33,9 @@ pub struct ReplCmdHandler { impl ReplCmdHandler { #[allow(clippy::unnecessary_wraps)] - pub fn init( - client: Box, - config: SharedConfig, - abort: SharedAbortSignal, - ) -> Result { + pub fn init(config: SharedConfig, abort: SharedAbortSignal) -> Result { let reply = RefCell::new(String::new()); Ok(Self { - client, config, reply, abort, @@ -57,9 +51,10 @@ impl ReplCmdHandler { } self.config.read().maybe_print_send_tokens(&input); let wg = WaitGroup::new(); + let client = init_client(self.config.clone())?; let ret = render_stream( &input, - self.client.as_ref(), + client.as_ref(), &self.config, true, self.abort.clone(), diff --git a/src/repl/mod.rs b/src/repl/mod.rs index ce640f8..311ca72 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -9,7 +9,6 @@ pub use self::abort::*; pub use self::handler::*; pub use self::init::Repl; -use crate::client::Client; use crate::config::SharedConfig; use crate::print_now; use crate::term; @@ -35,9 +34,9 @@ pub const REPL_COMMANDS: [(&str, &str); 13] = [ ]; impl Repl { - pub fn run(&mut self, client: Box, config: SharedConfig) -> Result<()> { + pub fn run(&mut self, config: SharedConfig) -> Result<()> { let abort = AbortSignal::new(); - let handler = ReplCmdHandler::init(client, config, abort.clone())?; + let handler = ReplCmdHandler::init(config, abort.clone())?; print_now!("Welcome to aichat {}\n", env!("CARGO_PKG_VERSION")); print_now!("Type \".help\" for more information.\n"); let mut already_ctrlc = false; -- cgit v1.2.3