summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-07-30 07:45:29 +0800
committerGitHub <noreply@github.com>2024-07-30 07:45:29 +0800
commitcc74be5d2163fbb1e9d57f85d5546857c6602446 (patch)
tree9897a88950ad6fc65dbd63f0cb9bbc9e7290d950 /src/utils
parent4c18e91165269970747bd2734b9b5db013ade2c2 (diff)
downloadaichat-cc74be5d2163fbb1e9d57f85d5546857c6602446.tar.gz
refactor: several improvements (#765)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/command.rs7
-rw-r--r--src/utils/mod.rs3
-rw-r--r--src/utils/request.rs3
3 files changed, 8 insertions, 5 deletions
diff --git a/src/utils/command.rs b/src/utils/command.rs
index 3876f3d..caf70c7 100644
--- a/src/utils/command.rs
+++ b/src/utils/command.rs
@@ -4,13 +4,18 @@ use std::{collections::HashMap, env, ffi::OsStr, path::Path, process::Command};
use anyhow::{anyhow, bail, Context, Result};
+lazy_static::lazy_static! {
+ pub static ref OS: String = detect_os();
+ pub static ref SHELL: Shell = detect_shell();
+}
+
pub fn detect_os() -> String {
let os = env::consts::OS;
if os == "linux" {
if let Ok(contents) = std::fs::read_to_string("/etc/os-release") {
for line in contents.lines() {
if let Some(id) = line.strip_prefix("ID=") {
- return format!("{os}/{id}");
+ return format!("{os} ({id})");
}
}
}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 0c1a0c4..a3aef22 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -21,11 +21,10 @@ pub use self::spinner::*;
use anyhow::{Context, Result};
use fancy_regex::Regex;
use is_terminal::IsTerminal;
-use lazy_static::lazy_static;
use std::{env, path::PathBuf, process};
use unicode_segmentation::UnicodeSegmentation;
-lazy_static! {
+lazy_static::lazy_static! {
pub static ref CODE_BLOCK_RE: Regex = Regex::new(r"(?ms)```\w*(.*)```").unwrap();
pub static ref IS_STDOUT_TERMINAL: bool = std::io::stdout().is_terminal();
}
diff --git a/src/utils/request.rs b/src/utils/request.rs
index 585018d..4a4e7c9 100644
--- a/src/utils/request.rs
+++ b/src/utils/request.rs
@@ -2,7 +2,6 @@ use super::*;
use anyhow::{bail, Result};
use http::header::CONTENT_TYPE;
-use lazy_static::lazy_static;
use std::{collections::HashMap, time::Duration};
use tokio::io::AsyncWriteExt;
@@ -11,7 +10,7 @@ pub const RECURSIVE_URL_LOADER: &str = "recursive_url";
pub const MEDIA_URL_EXTENSION: &str = "media_url";
pub const DEFAULT_EXTENSION: &str = "txt";
-lazy_static! {
+lazy_static::lazy_static! {
static ref CLIENT: Result<reqwest::Client> = {
let builder = reqwest::ClientBuilder::new().timeout(Duration::from_secs(30));
let builder = set_proxy(builder, None)?;