From fdca5855caab4efa402fcac963085262cd2fe024 Mon Sep 17 00:00:00 2001 From: Jakob Bagterp Date: Sat, 22 Apr 2023 12:18:00 +0200 Subject: [PATCH] Add Hex color instructions and examples to documentation. --- README.md | 33 ++++++++++++++++++++-- assets/images/examples/hex_custom_text.png | 3 ++ assets/images/examples/hex_full_text.png | 3 ++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 assets/images/examples/hex_custom_text.png create mode 100644 assets/images/examples/hex_full_text.png diff --git a/README.md b/README.md index d8086db9..2e313294 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,8 @@ Both options appear the same in the terminal: ![Example of terminal message with red text color](/assets/images/examples/color_custom_text_red.png) -### Print RGB and HSL Colors -Note that not all terminals support RGB or HSL colors. If your terminal does support such advanced colors, read on. +### Print RGB, HSL and Hex Colors +Note that not all terminals support RGB, HSL or Hex colors. If your terminal does support such advanced colors, read on. #### RGB Colors Try the `rgb` and `bg_rgb` methods for a full line of colored text. The values for red, green, blue can be an integer between `0-255`. @@ -171,6 +171,35 @@ How it appears in the terminal: ![Another example of text in HSL colors printed in a terminal window](/assets/images/examples/hsl_custom_text.png) +#### Hex Colors +Try the `hex` and `bg_hex` methods for a full line of colored text. Allowed Hex values are, for instance, `#00aaff` or `#0af`, alternatively without the hash sign as `00aaff` or `0af`. + +```python +from colorist import hex, bg_hex + +hex("I want this text in coral Hex colors", "#ff7f50") +bg_hex("I want this background in coral Hex colors", "#ff7f50") +``` + +How it appears in the terminal: + +![Example of text in Hex colors printed in a terminal window](/assets/images/examples/hex_full_text.png) + +Or customize the styling of text and background with the `ColorHex` and `BgColorHex` classes: + +```python +from colorist import ColorHex, BgColorHex + +watermelon_red = ColorHex("#ff5733") +bg_mint_green = BgColorHex("#99ff99") + +print(f"I want to use {watermelon_red}watermelon pink{watermelon_red.OFF} and {bg_mint_green}mint green{bg_mint_green.OFF} colors inside this paragraph") +``` + +How it appears in the terminal: + +![Another example of text in Hex colors printed in a terminal window](/assets/images/examples/hex_custom_text.png) + ### Print Effects and Other Styles In addition to colors, Colorist can also add effects when you print text in the terminal. How to print a full line of text with effects: diff --git a/assets/images/examples/hex_custom_text.png b/assets/images/examples/hex_custom_text.png new file mode 100644 index 00000000..97aee8e7 --- /dev/null +++ b/assets/images/examples/hex_custom_text.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:35a1cc33d324b4950a086598d093e8c6e0e3169fbc564d1e9b5203e5340b35a2 +size 12801 diff --git a/assets/images/examples/hex_full_text.png b/assets/images/examples/hex_full_text.png new file mode 100644 index 00000000..845b0a3e --- /dev/null +++ b/assets/images/examples/hex_full_text.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ade8502cc0b5c258fa8f34a110c2bb30ef9b835854961780ef7e14995db3faa6 +size 12060