def fgescape(color): nonlocal fg, fgd if fg == color: return '' fg = color r, g, b, _ = color fgd[color] = '\033[38;5;' + str(closest_color(r, g, b)) + 'm' return fgd[color]
def fgescape(color): nonlocal fg, fgd if fg == color: return '' fg=color r,g,b,_ = color fgd[color] = '\033[38;5;'+str(closest_color(r,g,b))+'m' return fgd[color]
def resolvecolor(): import os, sys, argparse, os.path, json, re from pixelterm.xtermcolors import closest_color # Resolve HTML-style hex RGB color codes to xterm-256color color numbers if len(sys.argv) != 2: print('Usage: resolvecolor.py #RRGGBB') exit() print(closest_color(*[int(s, 16) for s in re.match('#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups()]))
def bgescape(color): nonlocal bg, bgd if bg == color: return '' bg = color if color == (0, 0, 0, 0): return '\033[49m' if color in bgd: return bgd[color] r, g, b, _ = color bgd[color] = '\033[48;5;' + str(closest_color(r, g, b)) + 'm' return bgd[color]
def bgescape(color): nonlocal bg, bgd if bg == color: return '' bg=color if color == (0,0,0,0): return '\033[49m' if color in bgd: return bgd[color] r,g,b,_ = color bgd[color] = '\033[48;5;'+str(closest_color(r,g,b))+'m' return bgd[color]
def resolvecolor(): import os, sys, argparse, os.path, json, re from pixelterm.xtermcolors import closest_color # Resolve HTML-style hex RGB color codes to xterm-256color color numbers if len(sys.argv) != 2: print('Usage: resolvecolor.py #RRGGBB') exit() print( closest_color(*[ int(s, 16) for s in re.match( '#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})', sys.argv[1]).groups() ]))