Skip to content

Commit

Permalink
feat: support gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Jan 23, 2025
1 parent f37cb6e commit bac82cb
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 30 deletions.
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

0 comments on commit bac82cb

Please sign in to comment.