Skip to content

Commit d5e9aef

Browse files
authored
Merge pull request #99 from epage/anstream
fix: Improve terinal auto-detection
2 parents 3191fb1 + ea7df60 commit d5e9aef

5 files changed

Lines changed: 81 additions & 46 deletions

File tree

.clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.60.0" # MSRV
1+
msrv = "1.64.0" # MSRV

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ jobs:
4949
- name: Test Release
5050
run: cargo test --release
5151
msrv:
52-
name: "Check MSRV: 1.60.0"
52+
name: "Check MSRV: 1.64.0"
5353
runs-on: ubuntu-latest
5454
steps:
5555
- name: Checkout repository
5656
uses: actions/checkout@v3
5757
- name: Install Rust
5858
uses: dtolnay/rust-toolchain@stable
5959
with:
60-
toolchain: 1.60.0 # MSRV
60+
toolchain: 1.64.0 # MSRV
6161
- uses: Swatinem/rust-cache@v2
6262
- name: No default features
6363
run: cargo check --workspace --all-targets --no-default-features
@@ -107,7 +107,7 @@ jobs:
107107
- name: Install Rust
108108
uses: dtolnay/rust-toolchain@stable
109109
with:
110-
toolchain: 1.60.0 # MSRV
110+
toolchain: 1.64.0 # MSRV
111111
components: clippy
112112
- uses: Swatinem/rust-cache@v2
113113
- name: Install SARIF tools

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ homepage = "https://github.com/rust-cli/human-panic"
1414
categories = ["command-line-interface"]
1515
keywords = ["cli", "panic"]
1616
edition = "2018"
17-
rust-version = "1.60.0" # MSRV
17+
rust-version = "1.64.0" # MSRV
1818
include = [
1919
"build.rs",
2020
"src/**/*",
@@ -40,11 +40,11 @@ pre-release-replacements = [
4040
[features]
4141
default = ["color"]
4242
nightly = []
43-
color = ["dep:termcolor", "dep:concolor"]
43+
color = ["dep:anstyle", "dep:anstyle-stream"]
4444

4545
[dependencies]
46-
termcolor = { version = "1.2.0", optional = true }
47-
concolor = { version = "0.0.12", features = ["auto"], optional = true }
46+
anstyle = { version = "0.3.1", optional = true }
47+
anstyle-stream = { version = "0.2.1", optional = true }
4848
uuid = { version = "1.3.0", features = ["v4"], default-features = false }
4949
serde_derive = "1.0.152"
5050
toml = "0.7.2"

src/lib.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,32 +149,24 @@ impl Default for PanicStyle {
149149
/// Utility function that prints a message to our human users
150150
#[cfg(feature = "color")]
151151
pub fn print_msg<P: AsRef<Path>>(file_path: Option<P>, meta: &Metadata) -> IoResult<()> {
152-
use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
152+
use std::io::Write as _;
153153

154-
let stderr_support = concolor::get(concolor::Stream::Stdout);
155-
let choice = if stderr_support.color() {
156-
ColorChoice::Always
157-
} else {
158-
ColorChoice::Never
159-
};
160-
161-
let stderr = BufferWriter::stderr(choice);
162-
let mut buffer = stderr.buffer();
163-
buffer.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
164-
165-
write_msg(&mut buffer, file_path, meta)?;
154+
let stderr = anstyle_stream::stderr();
155+
let mut stderr = stderr.lock();
166156

167-
buffer.reset()?;
157+
write!(stderr, "{}", anstyle::AnsiColor::Red.render_fg())?;
158+
write_msg(&mut stderr, file_path, meta)?;
159+
write!(stderr, "{}", anstyle::Reset.render())?;
168160

169-
stderr.print(&buffer).unwrap();
170161
Ok(())
171162
}
172163

173164
#[cfg(not(feature = "color"))]
174165
pub fn print_msg<P: AsRef<Path>>(file_path: Option<P>, meta: &Metadata) -> IoResult<()> {
175-
let mut buffer = std::io::stderr();
166+
let stderr = std::io::stderr();
167+
let mut stderr = stderr.lock();
176168

177-
write_msg(&mut buffer, file_path, meta)?;
169+
write_msg(&mut stderr, file_path, meta)?;
178170

179171
Ok(())
180172
}

0 commit comments

Comments
 (0)