summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-21 07:57:02 +0800
committerGitHub <noreply@github.com>2024-04-21 07:57:02 +0800
commitc5506fe39377d864f80175821712b33949241583 (patch)
treeaa910f226cef456ff5a7652a8458c5193a6352de /src/main.rs
parentb3162a72b50f88d78ca3d57c1f8b3421cecfe2b4 (diff)
downloadaichat-c5506fe39377d864f80175821712b33949241583.tar.gz
refactor: tell user session compression (#426)
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 2 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs
index 600381b..6d5fe9b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,9 +25,8 @@ use is_terminal::IsTerminal;
use parking_lot::RwLock;
use std::io::{stderr, stdin, stdout, Read};
use std::sync::{mpsc, Arc};
-use std::time::Duration;
use std::{process, thread};
-use utils::Spinner;
+use utils::run_spinner;
fn main() -> Result<()> {
let cli = Cli::parse();
@@ -155,7 +154,7 @@ fn execute(config: &GlobalConfig, mut input: Input) -> Result<()> {
let client = init_client(config)?;
config.read().maybe_print_send_tokens(&input);
let (tx, rx) = mpsc::sync_channel::<()>(0);
- thread::spawn(move || run_spinner(rx));
+ thread::spawn(move || run_spinner(" Generating", rx));
let ret = client.send_message(input.clone());
tx.send(())?;
let mut eval_str = ret?;
@@ -246,18 +245,3 @@ fn create_input(
};
Ok(Some(input))
}
-
-fn run_spinner(rx: mpsc::Receiver<()>) -> Result<()> {
- let mut writer = stdout();
- let mut spinner = Spinner::new(" Generating");
- loop {
- spinner.step(&mut writer)?;
- if let Ok(()) = rx.try_recv() {
- spinner.stop(&mut writer)?;
- break;
- }
- thread::sleep(Duration::from_millis(50))
- }
- spinner.stop(&mut writer)?;
- Ok(())
-}