Skip to content

Commit bac82cb

Browse files
feat: support gradients
1 parent f37cb6e commit bac82cb

File tree

4 files changed

+276
-30
lines changed

4 files changed

+276
-30
lines changed

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ pub use crate::term::{
8484
};
8585
pub use crate::utils::{
8686
colors_enabled, colors_enabled_stderr, measure_text_width, pad_str, pad_str_with,
87-
set_colors_enabled, set_colors_enabled_stderr, style, truncate_str, Alignment, Attribute,
88-
Color, Emoji, Style, StyledObject,
87+
set_colors_enabled, set_colors_enabled_stderr, set_true_colors_enabled,
88+
set_true_colors_enabled_stderr, style, true_colors_enabled, true_colors_enabled_stderr,
89+
truncate_str, Alignment, Attribute, Color, Emoji, Style, StyledObject,
8990
};
9091

9192
#[cfg(feature = "ansi-parsing")]

src/term.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ impl TermFeatures<'_> {
7878
is_a_color_terminal(self.0)
7979
}
8080

81+
/// Check if true colors are supported by this terminal.
82+
pub fn true_colors_supported(&self) -> bool {
83+
is_a_true_color_terminal(self.0)
84+
}
85+
8186
/// Check if this terminal is an msys terminal.
8287
///
8388
/// This is sometimes useful to disable features that are known to not

src/unix_term.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
3636
}
3737
}
3838

39+
pub(crate) fn is_a_true_color_terminal(out: &Term) -> bool {
40+
if !is_a_color_terminal(out) {
41+
return false;
42+
}
43+
match env::var("COLORTERM") {
44+
Ok(term) => term == "truecolor" || term == "24bit",
45+
Err(_) => false,
46+
}
47+
}
48+
3949
fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
4050
let res = f();
4151
if res != 0 {

0 commit comments

Comments
 (0)