From 1100562e29f6476448b656dbddd4cf22505523f6 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Sun, 10 Mar 2024 14:59:14 +0100 Subject: Move back to JBMAFP --- content/notes/2023-05-25-show-xterm-colors.md | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 content/notes/2023-05-25-show-xterm-colors.md (limited to 'content/notes/2023-05-25-show-xterm-colors.md') diff --git a/content/notes/2023-05-25-show-xterm-colors.md b/content/notes/2023-05-25-show-xterm-colors.md new file mode 100644 index 0000000..79781e2 --- /dev/null +++ b/content/notes/2023-05-25-show-xterm-colors.md @@ -0,0 +1,83 @@ +--- +title: Display xterm color palette +url: /xterm-color-palette.html +date: 2023-05-25T12:00:00+02:00 +type: note +draft: false +--- + +- `bash xterm-palette.sh` - will show you number of max colors available +- `bash xterm-palette.sh -v` - will create a list of all colors with codes + +![xterm color palette](/assets/notes/xterm-palette.png) + +```sh +#!/usr/bin/env bash +# xterm-palette.sh + +trap 'tput sgr0' exit # Clean up even if user hits ^C + +function setfg () { + printf '\e[38;5;%dm' $1 +} + +function setbg () { + printf '\e[48;5;%dm' $1 +} + +function showcolors() { + # Given an integer, display that many colors + for ((i=0; i<$1; i++)) + do + printf '%4d ' $i + setbg $i + tput el + tput sgr0 + echo + done + tput sgr0 el +} + +# First, test if terminal supports OSC 4 at all. +printf '\e]4;%d;?\a' 0 +read -d $'\a' -s -t 0.1