From b4892d44e7309b1ae0db6d61a2e13d82c586483f Mon Sep 17 00:00:00 2001 From: Petr Portnov Date: Wed, 22 Nov 2023 16:47:48 +0300 Subject: [PATCH 1/2] feat: make `is_terminal` replaceable with `std` implementation --- Cargo.toml | 10 ++++++++-- src/lib.rs | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 65fd38eab..e4a2a7692 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ keywords = ["tab", "table", "format", "pretty", "print"] categories = ["command-line-interface"] license = "BSD-3-Clause" edition = "2018" +rust-version = "1.56.1" exclude = [ "prettytable-evcxr.png" ] @@ -23,9 +24,14 @@ codecov = { repository = "phsym/prettytable-rs", branch = "master", service = "g maintenance = { status = "passively-maintained" } [features] -default = ["win_crlf", "csv"] +# TODO: use `dep:` syntax here and below once MSRV is at least `1.60` +default = ["win_crlf", "csv", "legacy-is-terminal"] evcxr = [] win_crlf = [] +# This feature is inentionally opt-out (enabled by default) not to break older clients, +# although it may become no-op with a MSRV bummp (which is considered a minor change) and removed with a major update +# TODO: make this feature no-op once MSRV is at least `1.70` +legacy-is-terminal = ["is-terminal"] [[bin]] name = "main" @@ -39,6 +45,6 @@ name = "prettytable" unicode-width = "0.1" term = "0.7" lazy_static = "1.4" -is-terminal = "0.4" +is-terminal = { version = "0.4", optional = true } encode_unicode = "1.0" csv = { version = "1.1", optional = true } diff --git a/src/lib.rs b/src/lib.rs index e4fdb78d4..f2f831bec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -194,7 +194,11 @@ impl<'a> TableSlice<'a> { /// # Returns /// A `Result` holding the number of lines printed, or an `io::Error` if any failure happens pub fn print_tty(&self, force_colorize: bool) -> Result { + #[cfg(not(feature = "legacy-is-terminal"))] + use std::io::IsTerminal; + #[cfg(feature = "legacy-is-terminal")] use is_terminal::IsTerminal; + match (stdout(), io::stdout().is_terminal() || force_colorize) { (Some(mut o), true) => self.print_term(&mut *o), _ => self.print(&mut io::stdout()), From 27be74d327f055e7a6d6422de6cf46039383f2fe Mon Sep 17 00:00:00 2001 From: Petr Portnov Date: Thu, 30 Nov 2023 21:52:31 +0300 Subject: [PATCH 2/2] feat: make `is_terminal` replaceable with `std` via cfg --- Cargo.toml | 11 +++++------ src/lib.rs | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4a2a7692..8ba4f4b70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,13 +25,9 @@ maintenance = { status = "passively-maintained" } [features] # TODO: use `dep:` syntax here and below once MSRV is at least `1.60` -default = ["win_crlf", "csv", "legacy-is-terminal"] +default = ["win_crlf", "csv"] evcxr = [] win_crlf = [] -# This feature is inentionally opt-out (enabled by default) not to break older clients, -# although it may become no-op with a MSRV bummp (which is considered a minor change) and removed with a major update -# TODO: make this feature no-op once MSRV is at least `1.70` -legacy-is-terminal = ["is-terminal"] [[bin]] name = "main" @@ -45,6 +41,9 @@ name = "prettytable" unicode-width = "0.1" term = "0.7" lazy_static = "1.4" -is-terminal = { version = "0.4", optional = true } encode_unicode = "1.0" csv = { version = "1.1", optional = true } + +# TODO: remove it once MSRV is at least `1.70` +[target.'cfg(not(prettytable_is_terminal_implementation = "std"))'.dependencies] +is-terminal = "0.4" diff --git a/src/lib.rs b/src/lib.rs index f2f831bec..c34332400 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -194,9 +194,9 @@ impl<'a> TableSlice<'a> { /// # Returns /// A `Result` holding the number of lines printed, or an `io::Error` if any failure happens pub fn print_tty(&self, force_colorize: bool) -> Result { - #[cfg(not(feature = "legacy-is-terminal"))] + #[cfg(prettytable_is_terminal_implementation = "std")] use std::io::IsTerminal; - #[cfg(feature = "legacy-is-terminal")] + #[cfg(not(prettytable_is_terminal_implementation = "std"))] use is_terminal::IsTerminal; match (stdout(), io::stdout().is_terminal() || force_colorize) {