0

We know X11 has rgb.txt file that defines over 700 colors. Is there a similar file that defines the 256 colors (ie., hex code plus name) used in most terminal apps ?

sample lines:

255 250 250 snow 248 248 255 ghost white 248 248 255 GhostWhite 
4

1 Answer 1

0

Why make things so complicated? Use ANSI-colors instead.

Some Python code for you

#!/bin/env python3 CSI = "\x1B[" fg='3' bg='4' mode='5' def setRGB(fgbg, r, g=0, b=0, mde='2'): """ set a color on fg or bg mde=2 r;g;b mde=5 r - 0-255, for 256 color mode """ if mde=='5': return f"{CSI}{fgbg}8;{mde};{r}m" return f"{CSI}{fgbg}8;{mde};{r};{g};{b}m" if __name__ == "__main__": import sys for n in range(256): print(setRGB(fg,n,mde=mode)+setRGB(bg,254-n,mde=mode)+f' {n:3} ',end='') if (n+1)%16==0: print(f'{CSI}0m') print(f'{CSI}0m') 

If you intend to use it in windows CMD, add these lines after main:

 # Windows (i.e "nt"), needs ANSI initialized: import os if os.name=="nt": os.system("") # magic to init ANSI -sequences (= load ANSI.SYS for oldish CMD?) 
1
  • Thanks. Having read up on the topic of 256 colors, appreciate that it is based on ANSI colors. Commented Nov 7, 2024 at 6:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.