Skip to content

Commit b4892d4

Browse files
committed
feat: make is_terminal replaceable with std implementation
1 parent 4d66e6e commit b4892d4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ keywords = ["tab", "table", "format", "pretty", "print"]
1212
categories = ["command-line-interface"]
1313
license = "BSD-3-Clause"
1414
edition = "2018"
15+
rust-version = "1.56.1"
1516
exclude = [
1617
"prettytable-evcxr.png"
1718
]
@@ -23,9 +24,14 @@ codecov = { repository = "phsym/prettytable-rs", branch = "master", service = "g
2324
maintenance = { status = "passively-maintained" }
2425

2526
[features]
26-
default = ["win_crlf", "csv"]
27+
# TODO: use `dep:` syntax here and below once MSRV is at least `1.60`
28+
default = ["win_crlf", "csv", "legacy-is-terminal"]
2729
evcxr = []
2830
win_crlf = []
31+
# This feature is inentionally opt-out (enabled by default) not to break older clients,
32+
# although it may become no-op with a MSRV bummp (which is considered a minor change) and removed with a major update
33+
# TODO: make this feature no-op once MSRV is at least `1.70`
34+
legacy-is-terminal = ["is-terminal"]
2935

3036
[[bin]]
3137
name = "main"
@@ -39,6 +45,6 @@ name = "prettytable"
3945
unicode-width = "0.1"
4046
term = "0.7"
4147
lazy_static = "1.4"
42-
is-terminal = "0.4"
48+
is-terminal = { version = "0.4", optional = true }
4349
encode_unicode = "1.0"
4450
csv = { version = "1.1", optional = true }

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ impl<'a> TableSlice<'a> {
194194
/// # Returns
195195
/// A `Result` holding the number of lines printed, or an `io::Error` if any failure happens
196196
pub fn print_tty(&self, force_colorize: bool) -> Result<usize, Error> {
197+
#[cfg(not(feature = "legacy-is-terminal"))]
198+
use std::io::IsTerminal;
199+
#[cfg(feature = "legacy-is-terminal")]
197200
use is_terminal::IsTerminal;
201+
198202
match (stdout(), io::stdout().is_terminal() || force_colorize) {
199203
(Some(mut o), true) => self.print_term(&mut *o),
200204
_ => self.print(&mut io::stdout()),

0 commit comments

Comments
 (0)