diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/color-print/src/terminfo/style.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/color-print/src/terminfo/style.rs')
-rw-r--r-- | vendor/color-print/src/terminfo/style.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/color-print/src/terminfo/style.rs b/vendor/color-print/src/terminfo/style.rs new file mode 100644 index 000000000..5f14e2bac --- /dev/null +++ b/vendor/color-print/src/terminfo/style.rs @@ -0,0 +1,40 @@ +//! Lazy constants representing the ANSI codes for setting terminal styles, like bold, underline, +//! etc... +//! +//! Terminfo is used internally to guess the right codes. + +use lazy_static::lazy_static; +use terminfo_crate::{capability as cap, expand, Capability}; + +use crate::terminfo::TERMINFO; + +lazy_static! { + pub static ref CLEAR: String = style::<cap::ExitAttributeMode>(); + pub static ref BOLD: String = style::<cap::EnterBoldMode>(); + pub static ref DIM: String = style::<cap::EnterDimMode>(); + pub static ref BLINK: String = style::<cap::EnterBlinkMode>(); + pub static ref ITALICS: String = style::<cap::EnterItalicsMode>(); + pub static ref REVERSE: String = style::<cap::EnterReverseMode>(); + pub static ref UNDERLINE: String = style::<cap::EnterUnderlineMode>(); + pub static ref NO_ITALICS: String = style::<cap::ExitItalicsMode>(); + pub static ref NO_UNDERLINE: String = style::<cap::ExitUnderlineMode>(); +} + +/// Gets the ANSI code which sets the given style `T`. +fn style<'a, T>() -> String +where + T: Capability<'a> + AsRef<[u8]>, +{ + expand0::<'a, T>().unwrap_or_else(|| String::new()) +} + +/// Shortcut function for the `style()` function. +fn expand0<'a, T>() -> Option<String> +where + T: Capability<'a> + AsRef<[u8]>, +{ + let info = (*TERMINFO).as_ref()?; + let e = expand!(info.get::<T>()?.as_ref()).ok()?; + let s = std::str::from_utf8(&e).ok()?; + Some(s.to_owned()) +} |