2018-08-14 03:07 UTC

colorsysplus

NAME
    colorsysplus

DESCRIPTION
    This module supplements the standard colorsys module with functions for
    converting RGB to and from the following:
    
      * CMYK
      * hexadecimal color strings (e.g. HTML colors)
      * terminal color indices & ANSI escape codes
      * Xonotic color codes
    
    Some functionality may be incomplete. See the code and documention for details.

CLASSES
    builtins.object
        QuietUnbufferedUnblockedTerminal
    
    class QuietUnbufferedUnblockedTerminal(builtins.object)
     |  A wrapper object to configure the terminal for determining current RGB color
     |  values.
     |  
     |  Methods defined here:
     |  
     |  __enter__(self)
     |  
     |  __exit__(self, typ, val, traceback)
     |  
     |  __init__(self)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  term_init(self)
     |      Initialize the terminal.
     |      
     |      This does the following to facilitate terminal interaction for determining
     |      color values:
     |      
     |        * disables echo
     |        * disables buffering
     |        * disables blocking
     |      
     |      This should be called before invoking term_to_queried_rgb().
     |      
     |      Returns a terminal save state to pass to term_reset().
     |  
     |  term_reset(self)
     |      Reset the terminal.
     |      
     |      See term_init().
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)

FUNCTIONS
    ansi_sgr(fg=None, bg=None, term_colors=None, **kwargs)
        Get the ANSI escape sequence for the selected graphic rendition. This function
        accepts all keywords in ANSI_SGR_KEYWORDS_TO_PARAMS, the values of which
        should be boolean and indicate if that parameter should be set.
    
    ansi_sgr_color(color, fg=True, truecolor=False, term_colors=None)
        Get the appropriate sequence for the given color. If truecolor is false,
        colors will be cast to nearest color index.
    
    ansi_to_rgb(ansi, background=False, term_colors=None)
        Attempt to convert an ANSI escape code to RGB values.
    
    ansi_to_term(ansi, term_colors=None)
        Attempt to convert an ANSI escape code to a terminal color index.
    
    ansi_to_term_or_rgb(ansi, background=False)
        Attempt to parse a color value from an ANSI SGR escape sequence. This will
        return either a terminal color index or an RGB 3-tuple. Check the type.
        
        Parse background color if `background` is True.
    
    cmyk_to_rgb(c, m, y, k)
        Convert CMYK to RGB.
        
        This seems to be one of the most commonly used algorithms but CMYK values
        vary between printers and there is no canonical formula. Do not rely on these
        values for anything more than qualitative approximations.
    
    get_term_colors(timeout=1000)
        Iterate over the real RGB values for the current terminal.
    
    hex_to_rgb(hexstr, alpha=False)
        Convert a hexadecimal color string to RGB.
        
        Variable widths are recognized (e.g. #40f, #4400ff, #444000fff). The hash
        is optional.
        
        alpha: Set to true to indicate that the string contains alpha values.
    
    main(words)
    
    parse_ansi_sgr(ansi)
        Attempt to parse an ANSI SGR escape sequence. This will return a dictionary
        with entries that parallel the keyword arguments of ansi_sgr with some
        modifications where necessary, or None if the sequence is not an
        ANSI SGR escape.
    
    remove_ansi(s)
        Remove ANSI escape codes from a string.
    
    rgb_to_ansi(r, g, b, background=False, term_colors=None)
        Convert RGB values to ANSI (foreground) escapes.
    
    rgb_to_cmyk(r, g, b)
        Convert RGB to CMYK.
        
        This seems to be one of the most commonly used algorithms but CMYK values
        vary between printers and there is no canonical formula. Do not rely on these
        values for anything more than qualitative approximations.
    
    rgb_to_hex(r, g, b, alpha=None, width=2, include_hash=True)
        Convert RGB to a hexadecimal color string.
        
        alpha: Optional alpha channel value, in the range [0.0, 1.0].
        
        width: The number of characters to use for each field.
        
        include_hash: Prefix the string with a hash.
    
    rgb_to_term(r, g, b, n=256, colors=None)
        Convert RGB to a terminal color index.
        
        n:
          The number of colors to use. Currently only 256 is supported, but see
          "colors" below.
        
        colors:
          A list of RGB values corresponding to terminal colors. The index of the list
          is the terminal color. Returns the best approximation using a least squares
          method. The values should be in the range of 0.0 to 1.0.
        
        If n is not 256 and no colors are provided, returns None.
    
    rgb_to_xon(r, g, b, abbreviate=True)
        Convert RGB to a Xonotic color escape code.
    
    term_get_closest(arg, values)
        Return the value in values that is closest to arg in absolute distance.
        
        arg and values must lie in the range [0.0, 1.0] and values must be sorted in
        increasing order.
    
    term_get_closest_256_color(arg)
    
    term_get_closest_256_greyscale(arg)
    
    term_to_ansi(color)
        Convert terminal color to an ANSI escape code.
    
    term_to_queried_rgb(index, poll, timeout=-1, retries=5)
        Convert a terminal color index to RGB values.
        
        This should be called within a `with` block using
        QuietUnbufferedUnblockedTerminal.
        
        poll: poll object returned by QuietUnbufferedUnblockedTerminal's enter method.
        
        timeout: The timeout when polling.
        
        retries: The maximum number of retries when reading from stdout.
    
    term_to_rgb(index, n=256, colors=None)
        Convert a terminal color index to RGB.
        
        n: The number of colors to use. Currently only 256 is supported, but see
        "colors" below.
        
        colors: A list of RGB values corresponding to terminal colors. The index of
        the list is the terminal color index. Returns None on IndexError.
        
        If n is not 256 and no colors are provided, returns None.
    
    vector_distance_squared(a, b, c, u, v, w)
        Calculate Euclidian distance squared for the given components.
    
    wavelength_to_rgb(w, bg=(0.0, 0.0, 0.0), mode=None)
        Convert a wavelength (in nanometers) to RGB.
        
        This is a work in progress and will never be truly accurate due to the
        limitations of how colors are displayed on screens. Relevant links:
        
          * http://mintaka.sdsu.edu/GF/explain/optics/rendering.html
          * http://www.fourmilab.ch/documents/specrend/
          * http://www.physics.sfasu.edu/astro/color/spectra.html
          * http://mintaka.sdsu.edu/GF/explain/optics/color/color.html
        
        Note that I have not read all of them yet, so I hae not (yet) taken all of the
        advice given.
        
        bg: The background color into which the values should fade.
    
    xon_to_rgb(esc)
        Convert a Xonotic color escape code to RGB.
        
        These should omit the leading caret (^).

DATA
    ANSI_ESC = '\x1b'
    ANSI_SGR_KEYWORDS_TO_PARAMS = {'blink': '5', 'bold': '1', 'negative': ...
    ANSI_SGR_PARAMS_TO_KEYWORDS = {'0': 'reset', '1': 'bold', '5': 'blink'...
    ANSI_SGR_REGEX = re.compile('(\x1b\\[.+?m)')
    TERM_256_COLOR_STEPS = (0.0, 0.37254901960784315, 0.5294117647058824, ...
    TERM_256_GREYSCALE_STEPS = (0.03137254901960784, 0.07058823529411765, ...
    TERM_BASIC_COLORS = ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)...
    TERM_BASIC_COLOR_NAMES = ('black', 'red', 'green', 'yellow', 'blue', '...
    xon_long_to_short = {'x000': '0', 'x00f': '4', 'x0f0': '2', 'x0ff': '5...
    xon_short_to_long = {'0': 'x000', '1': 'xf00', '2': 'x0f0', '3': 'xff0...
Contact
echo xyne.archlinux.ca | sed 's/\./@/'
Feeds
Blog News
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0