Skip to content

Commit

Permalink
feat: make is_terminal replaceable with std via cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed Nov 30, 2023
1 parent b4892d4 commit 549bec1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ 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]]
Expand All @@ -45,6 +44,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 = { version = "0.4", optional = true }
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, Error> {
#[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) {
Expand Down

0 comments on commit 549bec1

Please sign in to comment.