summaryrefslogtreecommitdiffstats
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
authormtul0729 <52401682+mtul0729@users.noreply.github.com>2025-03-26 08:34:00 +0800
committerGitHub <noreply@github.com>2025-03-26 08:34:00 +0800
commitdd8f3e4528d45b7602df7ea6380b92a87dc4f711 (patch)
treefaf8368ed6e06a78547959414710848ff19a06ff /src/utils/mod.rs
parenta71e7c6be72965afd537aae076e0aee9e6f0755e (diff)
downloadaichat-dd8f3e4528d45b7602df7ea6380b92a87dc4f711.tar.gz
refactor: replace `lazy_static` with `std::sync::LazyLock` (#1246)
Diffstat (limited to 'src/utils/mod.rs')
-rw-r--r--src/utils/mod.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 38617a6..98f2da1 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -27,15 +27,22 @@ use fancy_regex::Regex;
use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher};
use is_terminal::IsTerminal;
use std::borrow::Cow;
+use std::sync::LazyLock;
use std::{env, path::PathBuf, process};
use unicode_segmentation::UnicodeSegmentation;
-lazy_static::lazy_static! {
- pub static ref CODE_BLOCK_RE: Regex = Regex::new(r"(?ms)```\w*(.*)```").unwrap();
- pub static ref THINK_TAG_RE: Regex = Regex::new(r"(?s)^\s*<think>.*?</think>(\s*|$)").unwrap();
- pub static ref IS_STDOUT_TERMINAL: bool = std::io::stdout().is_terminal();
- pub static ref NO_COLOR: bool = env::var("NO_COLOR").ok().and_then(|v| parse_bool(&v)).unwrap_or_default() || !*IS_STDOUT_TERMINAL;
-}
+pub static CODE_BLOCK_RE: LazyLock<Regex> =
+ LazyLock::new(|| Regex::new(r"(?ms)```\w*(.*)```").unwrap());
+pub static THINK_TAG_RE: LazyLock<Regex> =
+ LazyLock::new(|| Regex::new(r"(?s)^\s*<think>.*?</think>(\s*|$)").unwrap());
+pub static IS_STDOUT_TERMINAL: LazyLock<bool> = LazyLock::new(|| std::io::stdout().is_terminal());
+pub static NO_COLOR: LazyLock<bool> = LazyLock::new(|| {
+ env::var("NO_COLOR")
+ .ok()
+ .and_then(|v| parse_bool(&v))
+ .unwrap_or_default()
+ || !*IS_STDOUT_TERMINAL
+});
pub fn now() -> String {
chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false)