mirror of
https://github.com/tareqimbasher/cargo-seek.git
synced 2026-01-09 07:52:41 +08:00
Remove lazy_static crate
This commit is contained in:
parent
f6ff56322b
commit
928c3d6846
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -283,7 +283,6 @@ dependencies = [
|
||||
"human-panic",
|
||||
"indexmap",
|
||||
"json5",
|
||||
"lazy_static",
|
||||
"num-format",
|
||||
"open",
|
||||
"pretty_assertions",
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
name = "cargo-seek"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "Search and install cargo crates"
|
||||
description = "A terminal user interface for searching, adding and installing cargo crates"
|
||||
authors = ["Tareq Imbasher <https://github.com/tareqimbasher"]
|
||||
build = "build.rs"
|
||||
repository = "https://github.com/tareqimbasher/seekr"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z" # Optimize for size.
|
||||
strip = true # Automatically strip symbols from the binary.
|
||||
opt-level = "z"
|
||||
strip = true
|
||||
lto = true
|
||||
panic = "abort"
|
||||
|
||||
@ -37,7 +37,6 @@ futures = "0.3.30"
|
||||
human-panic = "2.0.1"
|
||||
indexmap = "2.8.0"
|
||||
json5 = "0.4.1"
|
||||
lazy_static = "1.5.0"
|
||||
num-format = "0.4.4"
|
||||
open = "5.3.0"
|
||||
pretty_assertions = { version = "1.4.1", features = ["unstable"] }
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{collections::HashMap, env, path::PathBuf};
|
||||
|
||||
use std::sync::LazyLock;
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use directories::ProjectDirs;
|
||||
use lazy_static::lazy_static;
|
||||
use ratatui::style::{Color, Modifier, Style};
|
||||
use serde::{de::Deserializer, Deserialize};
|
||||
use tracing::error;
|
||||
@ -57,17 +56,14 @@ pub struct Config {
|
||||
pub styles: Styles,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref PROJECT_NAME: String = env!("CARGO_CRATE_NAME").to_uppercase().to_string();
|
||||
pub static ref DATA_FOLDER: Option<PathBuf> =
|
||||
env::var(format!("{}_DATA", PROJECT_NAME.clone()))
|
||||
.ok()
|
||||
.map(PathBuf::from);
|
||||
pub static ref CONFIG_FOLDER: Option<PathBuf> =
|
||||
env::var(format!("{}_CONFIG", PROJECT_NAME.clone()))
|
||||
.ok()
|
||||
.map(PathBuf::from);
|
||||
}
|
||||
pub static PROJECT_NAME: LazyLock<String> = LazyLock::new(|| env!("CARGO_CRATE_NAME").to_uppercase().to_string());
|
||||
static DATA_FOLDER: LazyLock<Option<PathBuf>> = LazyLock::new(|| env::var(format!("{}_DATA", PROJECT_NAME.clone()))
|
||||
.ok()
|
||||
.map(PathBuf::from));
|
||||
static CONFIG_FOLDER: LazyLock<Option<PathBuf>> = LazyLock::new(|| env::var(format!("{}_CONFIG", PROJECT_NAME.clone()))
|
||||
.ok()
|
||||
.map(PathBuf::from));
|
||||
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Result<Self, config::ConfigError> {
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
use std::sync::LazyLock;
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||
|
||||
use crate::config;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref LOG_ENV: String = format!("{}_LOGLEVEL", config::PROJECT_NAME.clone());
|
||||
pub static ref LOG_FILE: String = format!("{}.log", env!("CARGO_PKG_NAME"));
|
||||
}
|
||||
static LOG_ENV: LazyLock<String> =
|
||||
LazyLock::new(|| format!("{}_LOGLEVEL", &*config::PROJECT_NAME));
|
||||
static LOG_FILE: LazyLock<String> = LazyLock::new(|| format!("{}.log", env!("CARGO_PKG_NAME")));
|
||||
|
||||
pub fn init() -> color_eyre::Result<()> {
|
||||
let directory = config::get_data_dir();
|
||||
std::fs::create_dir_all(directory.clone())?;
|
||||
let log_path = directory.join(LOG_FILE.clone());
|
||||
let log_path = directory.join(&*LOG_FILE);
|
||||
let log_file = std::fs::File::create(log_path)?;
|
||||
let env_filter = EnvFilter::builder().with_default_directive(tracing::Level::INFO.into());
|
||||
// If the `RUST_LOG` environment variable is set, use that as the default, otherwise use the
|
||||
@ -19,7 +19,7 @@ pub fn init() -> color_eyre::Result<()> {
|
||||
// errors, then this will return an error.
|
||||
let env_filter = env_filter
|
||||
.try_from_env()
|
||||
.or_else(|_| env_filter.with_env_var(LOG_ENV.clone()).from_env())?;
|
||||
.or_else(|_| env_filter.with_env_var(&*LOG_ENV).from_env())?;
|
||||
let file_subscriber = fmt::layer()
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
use chrono::{DateTime, Utc};
|
||||
use lazy_static::lazy_static;
|
||||
use num_format::{Locale, ToFormattedStr, ToFormattedString};
|
||||
use sys_locale::get_locale;
|
||||
|
||||
lazy_static! {
|
||||
// TODO maybe remove 1 or both libs?
|
||||
static ref LOCALE_STR: String = get_locale().unwrap_or(String::from("en-US"));
|
||||
// static ref LOCALE: Locale = Locale::from_str(LOCALE_STR.as_str()).unwrap_or(Locale::en);
|
||||
}
|
||||
static LOCALE_STR: LazyLock<String> = LazyLock::new(|| get_locale().unwrap_or(String::from("en-US")));
|
||||
|
||||
pub struct Util;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user