Skip to content

Commit f02463b

Browse files
committed
Switch from lazy_static to once_cell
1 parent 8e89a53 commit f02463b

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ansi-parsing = []
1919

2020
[dependencies]
2121
libc = "0.2.99"
22+
once_cell = "1.8"
2223
unicode-width = { version = "0.2", optional = true }
23-
lazy_static = "1.4.0"
2424

2525
[target.'cfg(windows)'.dependencies]
2626
encode_unicode = "1"

src/ansi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,18 @@ impl FusedIterator for AnsiCodeIterator<'_> {}
271271
mod tests {
272272
use super::*;
273273

274-
use lazy_static::lazy_static;
274+
use once_cell::sync::Lazy;
275275
use proptest::prelude::*;
276276
use regex::Regex;
277277

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

287287
impl<'a> PartialEq<Match<'a>> for regex::Match<'_> {
288288
fn eq(&self, other: &Match<'a>) -> bool {

src/unix_term.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use std::mem;
77
use std::os::unix::io::AsRawFd;
88
use std::str;
99

10+
#[cfg(not(target_os = "macos"))]
11+
use once_cell::sync::Lazy;
12+
1013
use crate::kb::Key;
1114
use crate::term::Term;
1215

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

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

353354
#[cfg(target_os = "macos")]
354355
pub fn wants_emoji() -> bool {

src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44
use std::fmt;
55
use std::sync::atomic::{AtomicBool, Ordering};
66

7-
use lazy_static::lazy_static;
7+
use once_cell::sync::Lazy;
88

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

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

25-
lazy_static! {
26-
static ref STDOUT_COLORS: AtomicBool = AtomicBool::new(default_colors_enabled(&Term::stdout()));
27-
static ref STDERR_COLORS: AtomicBool = AtomicBool::new(default_colors_enabled(&Term::stderr()));
28-
}
25+
static STDOUT_COLORS: Lazy<AtomicBool> =
26+
Lazy::new(|| AtomicBool::new(default_colors_enabled(&Term::stdout())));
27+
static STDERR_COLORS: Lazy<AtomicBool> =
28+
Lazy::new(|| AtomicBool::new(default_colors_enabled(&Term::stderr())));
2929

3030
/// Returns `true` if colors should be enabled for stdout.
3131
///

0 commit comments

Comments
 (0)