summaryrefslogtreecommitdiffstats
path: root/src/style.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/style.rs')
-rw-r--r--src/style.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/style.rs b/src/style.rs
index 693583e7..8ce78875 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -127,6 +127,22 @@ impl Style {
}
}
+/// Interpret `color_string` as a color specifier and return it painted accordingly.
+pub fn paint_color_string(
+ color_string: &str,
+ true_color: bool,
+) -> ansi_term::ANSIGenericString<str> {
+ if let Some(color) = color::parse_color(color_string, true_color) {
+ let style = ansi_term::Style {
+ background: Some(color),
+ ..ansi_term::Style::default()
+ };
+ style.paint(color_string)
+ } else {
+ ansi_term::ANSIGenericString::from(color_string)
+ }
+}
+
impl fmt::Display for Style {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.is_raw {