Skip to content

feat: support gradients #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ pub use crate::term::{
};
pub use crate::utils::{
colors_enabled, colors_enabled_stderr, measure_text_width, pad_str, pad_str_with,
set_colors_enabled, set_colors_enabled_stderr, style, truncate_str, Alignment, Attribute,
Color, Emoji, Style, StyledObject,
set_colors_enabled, set_colors_enabled_stderr, set_true_colors_enabled,
set_true_colors_enabled_stderr, style, true_colors_enabled, true_colors_enabled_stderr,
truncate_str, Alignment, Attribute, Color, Emoji, Style, StyledObject,
};

#[cfg(feature = "ansi-parsing")]
Expand Down
5 changes: 5 additions & 0 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ impl TermFeatures<'_> {
is_a_color_terminal(self.0)
}

/// Check if true colors are supported by this terminal.
pub fn true_colors_supported(&self) -> bool {
is_a_true_color_terminal(self.0)
}

/// Check if this terminal is an msys terminal.
///
/// This is sometimes useful to disable features that are known to not
Expand Down
10 changes: 10 additions & 0 deletions src/unix_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
}
}

pub(crate) fn is_a_true_color_terminal(out: &Term) -> bool {
if !is_a_color_terminal(out) {
return false;
}
match env::var("COLORTERM") {
Ok(term) => term == "truecolor" || term == "24bit",
Err(_) => false,
}
}

fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
let res = f();
if res != 0 {
Expand Down
Loading
Loading