Skip to content
Back to top
View this page
Edit this page

# xonsh.color_tools

Tools for color handling in xonsh.

This includes Convert values between RGB hex codes and xterm-256 color codes. Parts of this file were originally forked from Micah Elliott http://MicahElliott.com Copyright (C) 2011 Micah Elliott. All rights reserved. WTFPL http://sam.zoy.org/wtfpl/

class xonsh.color_tools.COLORS

  constants

  BOLD_GREEN = '{BOLD_GREEN}'
  BOLD_RED = '{BOLD_RED}'
  GREEN = '{GREEN}'
  RED = '{RED}'
  RESET = '{RESET}'

xonsh.color_tools.color_dist(x, y) → float

xonsh.color_tools.find_closest_color(x, palette)

xonsh.color_tools.iscolor(s)

  Tests if a string is a valid color

xonsh.color_tools.make_palette(strings)

  Makes a color palette from a collection of strings.

xonsh.color_tools.rgb2short(rgb)

  Find the closest ANSI 256 approximation to the given RGB value.

      >>> rgb2short('123456')
      ('23', '005f5f')
      >>> rgb2short('ffffff')
      ('231', 'ffffff')
      >>> rgb2short('0DADD6') # vimeo logo
      ('38', '00afd7')

  Parameters:
    rgb Hex code representing an RGB value, eg, ‘abcdef’
  Returns:
    Tuple of String between 0 and 255 (compatible with xterm) and
    hex code (length-6).

xonsh.color_tools.rgb_to_256(rgb)

  Find the closest ANSI 256 approximation to the given RGB value.

      >>> rgb2short('123456')
      ('23', '005f5f')
      >>> rgb2short('ffffff')
      ('231', 'ffffff')
      >>> rgb2short('0DADD6') # vimeo logo
      ('38', '00afd7')

  Parameters:
    rgb Hex code representing an RGB value, eg, ‘abcdef’
  Returns:
    Tuple of String between 0 and 255 (compatible with xterm) and
    hex code (length-6).

xonsh.color_tools.rgb_to_ints(rgb)

xonsh.color_tools.short2rgb(short)

xonsh.color_tools.short_to_ints(short)

  Coverts a short (256) color to a 3-tuple of ints.

xonsh.color_tools.warn_deprecated_no_color()

  Show a warning once if NO_COLOR was used instead of RESET.