Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from lazy_static to once_cell #218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ansi-parsing = []
[dependencies]
libc = "0.2.99"
unicode-width = { version = "0.1", optional = true }
lazy_static = "1.4.0"
once_cell = "1"

[target.'cfg(windows)'.dependencies]
encode_unicode = "0.3"
Expand Down
14 changes: 7 additions & 7 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,18 @@ impl<'a> FusedIterator for AnsiCodeIterator<'a> {}
mod tests {
use super::*;

use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use proptest::prelude::*;
use regex::Regex;

// The manual dfa `State` is a handwritten translation from the previously used regex. That
// regex is kept here and used to ensure that the new matches are the same as the old
lazy_static! {
static ref STRIP_ANSI_RE: Regex = Regex::new(
r"[\x1b\x9b]([()][012AB]|[\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><])",
)
.unwrap();
}
static STRIP_ANSI_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"[\x1b\x9b]([()][012AB]|[\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><])",
)
.unwrap()
});

impl<'a, 'b> PartialEq<Match<'a>> for regex::Match<'b> {
fn eq(&self, other: &Match<'a>) -> bool {
Expand Down
13 changes: 7 additions & 6 deletions src/unix_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use std::mem;
use std::os::unix::io::AsRawFd;
use std::str;

#[cfg(not(target_os = "macos"))]
use once_cell::sync::Lazy;

use crate::kb::Key;
use crate::term::Term;

Expand Down Expand Up @@ -343,12 +346,10 @@ pub fn key_from_utf8(buf: &[u8]) -> Key {
}

#[cfg(not(target_os = "macos"))]
lazy_static::lazy_static! {
static ref IS_LANG_UTF8: bool = match std::env::var("LANG") {
Ok(lang) => lang.to_uppercase().ends_with("UTF-8"),
_ => false,
};
}
static IS_LANG_UTF8: Lazy<bool> = Lazy::new(|| match std::env::var("LANG") {
Ok(lang) => lang.to_uppercase().ends_with("UTF-8"),
_ => false,
});

#[cfg(target_os = "macos")]
pub fn wants_emoji() -> bool {
Expand Down
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::env;
use std::fmt;
use std::sync::atomic::{AtomicBool, Ordering};

use lazy_static::lazy_static;
use once_cell::sync::Lazy;

use crate::term::{wants_emoji, Term};

Expand All @@ -22,10 +22,10 @@ fn default_colors_enabled(out: &Term) -> bool {
|| &env::var("CLICOLOR_FORCE").unwrap_or_else(|_| "0".into()) != "0"
}

lazy_static! {
static ref STDOUT_COLORS: AtomicBool = AtomicBool::new(default_colors_enabled(&Term::stdout()));
static ref STDERR_COLORS: AtomicBool = AtomicBool::new(default_colors_enabled(&Term::stderr()));
}
static STDOUT_COLORS: Lazy<AtomicBool> =
Lazy::new(|| AtomicBool::new(default_colors_enabled(&Term::stdout())));
static STDERR_COLORS: Lazy<AtomicBool> =
Lazy::new(|| AtomicBool::new(default_colors_enabled(&Term::stderr())));

/// Returns `true` if colors should be enabled for stdout.
///
Expand Down