Skip to content

Commit ae51fc8

Browse files
authored
Merge pull request #64 from epage/anstream
fix: Improve terminal color detection
2 parents 41e6c3b + 6b37844 commit ae51fc8

File tree

8 files changed

+215
-145
lines changed

8 files changed

+215
-145
lines changed

Cargo.lock

Lines changed: 109 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ clap = { version = "4.1.4", features = ["derive", "wrap_help"] }
3333
clap-verbosity-flag = "2.0"
3434
log = "0.4"
3535
env_logger = { version = "0.10", default-features = false, features = ["color"] }
36-
yansi = "0.5.1"
37-
concolor = "0.0.11"
38-
concolor-clap = { version = "0.0.13", features = ["api_unstable"] }
36+
concolor = "0.1.1"
37+
concolor-clap = { version = "0.1.0", features = ["api"] }
3938
proc-exit = "2"
4039
human-panic = "1"
4140
anyhow = "1.0.68"
4241
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "regex-fancy"] }
4342
terminal_size = "0.2.3"
4443
textwrap = "0.16.0"
45-
anstyle = "0.2.5"
44+
anstyle = "0.3.1"
45+
anstyle-stream = "0.2.2"
46+
is-terminal = "0.4.4"
4647
content_inspector = "0.2.4"
4748
encoding = "0.2.33"
4849
git-config-env = "0.1.2"
4950
shlex = "1.1.0"
50-
atty = "0.2.14"
51-
anstyle-syntect = "0.1.2"
51+
anstyle-syntect = "0.2.0"
5252
bincode = "1.3.3"
5353
serde = { version = "1.0.152", features = ["derive"] }
5454
flate2 = "1.0.25"

src/assets/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn to_anstyle_color(color: syntect::highlighting::Color) -> Option<anstyle::
4040
// TODO: When ansi_term adds support for bright variants using codes
4141
// 90-97 (foreground) and 100-107 (background), we should use those
4242
// for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff.
43-
n => anstyle::XTermColor(n).into(),
43+
n => anstyle::Ansi256Color(n).into(),
4444
})
4545
} else if color.a == 1 {
4646
// Themes can specify the terminal's default foreground/background color

src/blame.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ pub fn blame(
1111
file_path: &std::path::Path,
1212
config: &mut Config,
1313
args: &crate::args::Args,
14-
colored_stdout: bool,
15-
_colored_stderr: bool,
1614
) -> proc_exit::ExitResult {
15+
let colored_stdout = anstyle_stream::AutoStream::choice(&std::io::stdout())
16+
!= anstyle_stream::ColorChoice::Never;
1717
let total_width = terminal_size::terminal_size()
1818
.map(|(w, _h)| w.0)
1919
.or_else(|| std::env::var_os("COLUMNS").and_then(|s| s.to_str()?.parse::<u16>().ok()))
@@ -470,7 +470,7 @@ fn gutter_style(theme: &syntect::highlighting::Theme) -> anstyle::Style {
470470
.settings
471471
.gutter_foreground
472472
.map(crate::assets::to_anstyle_color)
473-
.unwrap_or_else(|| Some(anstyle::XTermColor(DEFAULT_GUTTER_COLOR).into()));
473+
.unwrap_or_else(|| Some(anstyle::Ansi256Color(DEFAULT_GUTTER_COLOR).into()));
474474

475475
anstyle::Style::new().fg_color(fg_color)
476476
}

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn dump_config(output_path: &std::path::Path, config: &mut Config) -> proc_e
1616

1717
if output_path == std::path::Path::new("-") {
1818
use std::io::Write;
19-
std::io::stdout()
19+
anstyle_stream::stdout()
2020
.write_all(output.as_bytes())
2121
.with_code(proc_exit::Code::FAILURE)?;
2222
} else {

0 commit comments

Comments
 (0)