Created
December 4, 2025 05:20
-
-
Save AlexAtkinson/54caf9cf424debffc6438d5ef5d56c9a to your computer and use it in GitHub Desktop.
TrueColor Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Truecolor demo | |
| # Thanks to those who I've taken inspiration from. | |
| # My Adds: | |
| # - int bounding | |
| # - text overlay for single-line output with contextual hint | |
| __color_truecolor_demo() { | |
| local TXT FG COLUMN COLUMNS FILL_L FILL_R R G B | |
| TXT="This will be a smooth gradient if truecolor is supported." | |
| COLUMNS="${COLUMNS:-$(tput cols || 120)}" | |
| FILL_L="$(printf '%*s' "$(((COLUMNS - ${#TXT}) / 2))")" | |
| FILL_R="$(printf '%*s' "$(((COLUMNS - ${#TXT}) / 2))")" | |
| [[ $((${#TXT}%2)) -eq 1 ]] && FILL_R="$(printf '%*s' "$((((COLUMNS - ${#TXT}) / 2) +1 ))")" | |
| FG=$(printf '%s' "$FILL_L"; printf '%s' "$TXT"; printf '%s' "$FILL_R") | |
| for ((COLUMN=0; COLUMN<COLUMNS; COLUMN++)); do | |
| # Iterate RGB values ; Ensure ints stays within range 0..255 | |
| ((R=255-(COLUMN*255/COLUMNS))) ; ((R<0))&&((R=255-(RB+255))); ((R>255))&&((R=R-(R-255))) | |
| ((G=COLUMN*510/COLUMNS)) ; ((G<0))&&((G=255-(G+255))); ((G>255))&&((G=G-(G-255))) | |
| ((B=COLUMN*255/COLUMNS)) ; ((B<0))&&((B=255-(B+255))); ((B>255))&&((B=B-(B-255))) | |
| printf "\e[48;2;%d;%d;%dm" $R $G $B # BG | |
| printf "\e[38;2;%d;%d;%d;1m" $R 0 $B # FG Color | |
| printf "%s\e[0m" "${FG:${COLUMN}:1}" # FG Content | |
| #printf "%s\e[0m" " " # No FG Content | |
| done | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EG:
