Skip to content

Commit 6296420

Browse files
committed
feat: alert_color tty support, use rustc_hash instead std::hash
1 parent f7606b9 commit 6296420

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ edition = "2021"
66
[dependencies]
77
prost = "0.10"
88
url = "2"
9-
supports-color = "1"
9+
atty = "0.2"
1010
parking_lot = "0.12"
1111
dashmap = "5"
1212
crossbeam-channel = "0.5"
13-
13+
rustc-hash = "1"
1414

1515
[build-dependencies]
1616
prost-build = "0.10"

src/embedded.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::ffi::OsStr;
22

3+
use atty::Stream;
4+
35
use crate::{
46
channel::Channel,
57
host::ImporterRegistry,
@@ -47,7 +49,7 @@ impl Embedded {
4749
let request = CompileRequest {
4850
style: options.style as i32,
4951
source_map: options.source_map,
50-
alert_color: options.alert_color,
52+
alert_color: options.alert_color.unwrap_or(atty::is(Stream::Stdout)),
5153
alert_ascii: options.alert_ascii,
5254
verbose: options.verbose,
5355
quiet_deps: options.quiet_deps,
@@ -84,7 +86,10 @@ impl Embedded {
8486
let request = CompileRequest {
8587
style: options.common.style as i32,
8688
source_map: options.common.source_map,
87-
alert_color: options.common.alert_color,
89+
alert_color: options
90+
.common
91+
.alert_color
92+
.unwrap_or(atty::is(Stream::Stdout)),
8893
alert_ascii: options.common.alert_ascii,
8994
verbose: options.common.verbose,
9095
quiet_deps: options.common.quiet_deps,

src/host/importer_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use rustc_hash::FxHashMap;
22

33
use crate::{
44
options::{FileImporter, Importer, ImporterOptions, SassImporter},
@@ -20,9 +20,9 @@ pub struct ImporterRegistry {
2020
/// The next ID to use for an importer.
2121
id: u32,
2222
/// A map from importer IDs to their corresponding importers.
23-
importers_by_id: HashMap<u32, Box<dyn Importer>>,
23+
importers_by_id: FxHashMap<u32, Box<dyn Importer>>,
2424
/// A map from file importer IDs to their corresponding importers.
25-
file_importers_by_id: HashMap<u32, Box<dyn FileImporter>>,
25+
file_importers_by_id: FxHashMap<u32, Box<dyn FileImporter>>,
2626
}
2727

2828
impl ImporterRegistry {

src/options.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::fmt::Debug;
22

3-
use url::Url;
4-
53
use crate::{
64
protocol::{OutputStyle, SourceSpan, Syntax},
7-
Result,
5+
Result, Url,
86
};
97

108
/// https://sass-lang.com/documentation/js-api/interfaces/Options
@@ -13,7 +11,7 @@ pub struct Options {
1311
/// https://sass-lang.com/documentation/js-api/interfaces/Options#alertAscii
1412
pub alert_ascii: bool,
1513
/// https://sass-lang.com/documentation/js-api/interfaces/Options#alertColor
16-
pub alert_color: bool,
14+
pub alert_color: Option<bool>,
1715
// /// https://sass-lang.com/documentation/js-api/interfaces/Options#functions
1816
// pub functions
1917
/// https://sass-lang.com/documentation/js-api/interfaces/Options#importers
@@ -40,7 +38,7 @@ impl Default for Options {
4038
fn default() -> Self {
4139
Self {
4240
alert_ascii: false,
43-
alert_color: false,
41+
alert_color: None,
4442
load_paths: None,
4543
importers: None,
4644
logger: None,
@@ -74,7 +72,7 @@ impl OptionsBuilder {
7472
}
7573

7674
pub fn alert_color(mut self, arg: bool) -> Self {
77-
self.options.alert_color = arg;
75+
self.options.alert_color = Some(arg);
7876
self
7977
}
8078

@@ -241,7 +239,7 @@ impl StringOptionsBuilder {
241239
}
242240

243241
pub fn alert_color(mut self, arg: bool) -> Self {
244-
self.options.alert_color = arg;
242+
self.options.alert_color = Some(arg);
245243
self
246244
}
247245

0 commit comments

Comments
 (0)