Skip to content

Commit

Permalink
Drop once_cell because of MSRV bump (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Sep 28, 2022
1 parent ba208a0 commit 34b1e3d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -17,11 +17,11 @@ windows-console-colors = ["ansi-parsing", "regex", "winapi-util"]
ansi-parsing = []

[dependencies]
once_cell = "1"
libc = "0.2.30"
terminal_size = "0.1.14"
regex = { version = "1.4.2", optional = true, default-features = false, features = ["std"] }
unicode-width = { version = "0.1", optional = true }
lazy_static = "1.4.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase", "winuser", "consoleapi", "processenv", "wincon"] }
Expand Down
14 changes: 7 additions & 7 deletions src/ansi.rs
Expand Up @@ -271,18 +271,18 @@ impl<'a> FusedIterator for AnsiCodeIterator<'a> {}
mod tests {
use super::*;

use once_cell::sync::Lazy;
use lazy_static::lazy_static;
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
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()
});
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();
}

impl<'a, 'b> PartialEq<Match<'a>> for regex::Match<'b> {
fn eq(&self, other: &Match<'a>) -> bool {
Expand Down
7 changes: 4 additions & 3 deletions src/unix_term.rs
Expand Up @@ -271,11 +271,12 @@ pub fn key_from_utf8(buf: &[u8]) -> Key {
}

#[cfg(not(target_os = "macos"))]
static IS_LANG_UTF8: once_cell::sync::Lazy<bool> =
once_cell::sync::Lazy::new(|| match std::env::var("LANG") {
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,
});
};
}

#[cfg(target_os = "macos")]
pub fn wants_emoji() -> bool {
Expand Down
11 changes: 6 additions & 5 deletions src/utils.rs
Expand Up @@ -4,8 +4,9 @@ use std::env;
use std::fmt;
use std::sync::atomic::{AtomicBool, Ordering};

use lazy_static::lazy_static;

use crate::term::{wants_emoji, Term};
use once_cell::sync::Lazy;

#[cfg(feature = "ansi-parsing")]
use crate::ansi::{strip_ansi_codes, AnsiCodeIterator};
Expand All @@ -21,10 +22,10 @@ fn default_colors_enabled(out: &Term) -> bool {
|| &env::var("CLICOLOR_FORCE").unwrap_or_else(|_| "0".into()) != "0"
}

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())));
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()));
}

/// Returns `true` if colors should be enabled for stdout.
///
Expand Down
14 changes: 6 additions & 8 deletions src/windows_term.rs
Expand Up @@ -37,17 +37,15 @@ use crate::common_term;
use crate::kb::Key;
use crate::term::{Term, TermTarget};

#[cfg(feature = "windows-console-colors")]
use once_cell::sync::Lazy;
#[cfg(feature = "windows-console-colors")]
use regex::Regex;

#[cfg(feature = "windows-console-colors")]
static INTENSE_COLOR_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\x1b\[(3|4)8;5;(8|9|1[0-5])m").unwrap());
#[cfg(feature = "windows-console-colors")]
static NORMAL_COLOR_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\x1b\[(3|4)([0-7])m").unwrap());
#[cfg(feature = "windows-console-colors")]
static ATTR_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\x1b\[([1-8])m").unwrap());
lazy_static::lazy_static! {
static ref INTENSE_COLOR_RE: Regex = Regex::new(r"\x1b\[(3|4)8;5;(8|9|1[0-5])m").unwrap();
static ref NORMAL_COLOR_RE: Regex = Regex::new(r"\x1b\[(3|4)([0-7])m").unwrap();
static ref ATTR_RE: Regex = Regex::new(r"\x1b\[([1-8])m").unwrap();
}

const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 0x4;
pub const DEFAULT_WIDTH: u16 = 79;
Expand Down

0 comments on commit 34b1e3d

Please sign in to comment.