ansi-0.1.3/0000755000076500000240000000000012551260665013232 5ustar wijnandstaff00000000000000ansi-0.1.3/ansi/0000755000076500000240000000000012551260665014164 5ustar wijnandstaff00000000000000ansi-0.1.3/ansi/__init__.py0000644000076500000240000000000012551260444016256 0ustar wijnandstaff00000000000000ansi-0.1.3/ansi/_compat.py0000644000076500000240000000017012551260444016151 0ustar wijnandstaff00000000000000import sys PY2 = sys.version_info[0] == 2 if PY2: string_types = basestring else: string_types = (str, bytes) ansi-0.1.3/ansi/color.py0000644000076500000240000000016112551260444015645 0ustar wijnandstaff00000000000000#pylint: disable=C0111,W0611,W0614 from sys import modules import ansi.colour modules["ansi.color"] = ansi.colouransi-0.1.3/ansi/colour/0000755000076500000240000000000012551260665015467 5ustar wijnandstaff00000000000000ansi-0.1.3/ansi/colour/__init__.py0000644000076500000240000000003412551260444017570 0ustar wijnandstaff00000000000000__all__ = ['bg', 'fg', 'fx']ansi-0.1.3/ansi/colour/base.py0000644000076500000240000000153012551260444016745 0ustar wijnandstaff00000000000000#pylint: disable=C0103,R0903 from ansi.sequence import sequence from ansi._compat import string_types __all__ = ['Graphic'] class Graphic(object): ''' Compose a Select Graphic Rendition (SGR) ANSI escape sequence. ''' def __init__(self, *values): self.values = values self.sequence = sequence('m', fields=-1)(*values) def __add__(self, their): if isinstance(their, str): return ''.join([str(self), their]) elif isinstance(their, string_types): raise ValueError('Use str, nothing else.') else: return Graphic(*(self.values + their.values)) def __call__(self, text, reset=True): result = self.sequence + text if reset: result += str(Graphic('0')) return result def __str__(self): return self.sequence ansi-0.1.3/ansi/colour/bg.py0000644000076500000240000000254512551260444016432 0ustar wijnandstaff00000000000000#pylint: disable=C0103,R0903 from ansi.colour.base import Graphic from ansi.colour.fx import bold # ECMA-048 standard names black = Graphic('40') red = Graphic('41') green = Graphic('42') yellow = Graphic('43') blue = Graphic('44') magenta = Graphic('45') cyan = Graphic('46') white = Graphic('47') default = Graphic('49') # ECMA-048 bold variants boldblack = bold + black boldred = bold + red boldgreen = bold + green boldyellow = bold + yellow boldblue = bold + blue boldmagenta = bold + magenta boldcyan = bold + cyan boldwhite = bold + white # Convenience wrappers brown = yellow # Not in ANSI/ECMA-048 standard grey = white # Not in ANSI/ECMA-048 standard gray = white # US English darkgrey = boldblack darkgray = boldblack # US English brightred = boldred brightgreen = boldgreen brightyellow = boldyellow brightbrown = boldyellow # Not in ANSI/ECMA-048 standard brightblue = boldblue brightmagenta = boldmagenta brightcyan = boldcyan brightwhite = boldwhite brightgrey = boldwhite # Not in ANSI/ECMA-048 standard brightgray = boldwhite # Us English ansi-0.1.3/ansi/colour/fg.py0000644000076500000240000000254612551260444016437 0ustar wijnandstaff00000000000000#pylint: disable=C0103,R0903 from ansi.colour.base import Graphic from ansi.colour.fx import bold # ECMA-048 standard names black = Graphic('30') red = Graphic('31') green = Graphic('32') yellow = Graphic('33') blue = Graphic('34') magenta = Graphic('35') cyan = Graphic('36') white = Graphic('37') default = Graphic('39') # ECMA-048 bold variants boldblack = bold + black boldred = bold + red boldgreen = bold + green boldyellow = bold + yellow boldblue = bold + blue boldmagenta = bold + magenta boldcyan = bold + cyan boldwhite = bold + white # Convenience wrappers brown = yellow # Not in ANSI/ECMA-048 standard grey = white # Not in ANSI/ECMA-048 standard gray = white # US English darkgrey = boldblack darkgray = boldblack # US English brightred = boldred brightgreen = boldgreen brightyellow = boldyellow brightbrown = boldyellow # Not in ANSI/ECMA-048 standard brightblue = boldblue brightmagenta = boldmagenta brightcyan = boldcyan brightwhite = boldwhite brightgrey = boldwhite # Not in ANSI/ECMA-048 standard brightgray = boldwhite # Us English ansi-0.1.3/ansi/colour/fx.py0000644000076500000240000000263212551260444016454 0ustar wijnandstaff00000000000000#pylint: disable=C0103,R0903 from ansi.colour.base import Graphic # ECMA-048 standard names reset = Graphic('0') bold = Graphic('1') faint = Graphic('2') italic = Graphic('3') underline = Graphic('4') blink_slow = Graphic('5') blink = Graphic('6') negative = Graphic('7') conceal = Graphic('8') crossed_out = Graphic('9') font_reset = Graphic('10') font_1 = Graphic('11') font_2 = Graphic('12') font_3 = Graphic('13') font_4 = Graphic('14') font_5 = Graphic('15') font_6 = Graphic('16') font_7 = Graphic('17') font_8 = Graphic('18') font_9 = Graphic('19') fraktur = Graphic('20') gothic = Graphic('20') underline_double = Graphic('21') normal = Graphic('22') not_italic = Graphic('23') not_fraktur = Graphic('23') not_gothic = Graphic('23') not_underline = Graphic('24') steady = Graphic('25') positive = Graphic('27') reveal = Graphic('28') framed = Graphic('51') encircled = Graphic('52') overlined = Graphic('53') not_framed = Graphic('54') not_encircled = Graphic('54') not_overlined = Graphic('55') # Convenience wrappers inverse = negative bright = bold not_blink = steady blink_off = steady ansi-0.1.3/ansi/colour/rgb.py0000644000076500000240000000331412551260444016607 0ustar wijnandstaff00000000000000from ansi.sequence import sequence ANSI_COLOURS = ( (0x00, 0x00, 0x00), (0xcd, 0x00, 0x00), (0x00, 0xcd, 0x00), (0xcd, 0xcd, 0x00), (0x00, 0x00, 0xee), (0xcd, 0x00, 0xcd), (0x00, 0xcd, 0xcd), (0xe5, 0xe5, 0xe5), (0x7f, 0x7f, 0x7f), (0xff, 0x00, 0x00), (0x00, 0xff, 0x00), (0xff, 0xff, 0x00), (0x5c, 0x5c, 0xff), (0xff, 0x00, 0xff), (0x00, 0xff, 0xff), (0xff, 0xff, 0xff), ) def rgb_distance(rgb1, rgb2): ''' Calculate the distance between two RGB sequences. ''' return sum(map(lambda c: (c[0] - c[1]) ** 2, zip(rgb1, rgb2))) def rgb_reduce(r, g, b, mode=8): ''' Convert an RGB colour to 8 or 16 colour ANSI graphics. ''' colours = ANSI_COLOURS[:mode] matches = [(rgb_distance(c, map(int, [r, g, b])), i) for i, c in enumerate(colours)] matches.sort() return sequence('m')(str(30 + matches[0][1])) def rgb8(r, g, b): ''' Convert an RGB colour to 8 colour ANSI graphics. ''' return rgb_reduce(r, g, b, 8) def rgb16(r, g, b): ''' Convert an RGB colour to 16 colour ANSI graphics. ''' return rgb_reduce(r, g, b, 16) def rgb256(r, g, b): ''' Convert an RGB colour to 256 colour ANSI graphics. ''' grey = False poss = True step = 2.5 while poss: # As long as the colour could be grey scale if r < step or g < step or b < step: grey = r < step and g < step and b < step poss = False step += 42.5 if grey: colour = 232 + int(float(sum([r, g, b]) / 33.0)) else: colour = sum([16] + [int (6 * float(val) / 256) * mod for val, mod in ((r, 36), (g, 6), (b, 1))]) return sequence('m', fields=3)(38, 5, colour) ansi-0.1.3/ansi/cursor.py0000644000076500000240000000075612551260444016056 0ustar wijnandstaff00000000000000#pylint: disable=C0103 from ansi.sequence import sequence # Cursor movement up = sequence('A') down = sequence('B') forward = sequence('C') back = sequence('D') next_line = sequence('E') prev_line = sequence('F') goto_x = sequence('H') goto = sequence('G', 2) erase = sequence('J') erase_data = erase erase_line = sequence('K') scroll_up = sequence('S') scroll_down = sequence('T') save_cursor = sequence('s') load_cursor = sequence('u') ansi-0.1.3/ansi/sequence.py0000644000076500000240000000103412551260444016337 0ustar wijnandstaff00000000000000CSI = '\x1b[' def sequence(letter, fields=1, default=[]): def _sequence(*values): output = list(values) if fields >= 0 and len(output) > fields: raise ValueError('Invalid number of fields, got %d expected %d' % (len(output), fields)) while len(output) < fields and len(default) > len(output): output.append(fields[len(default) - 1]) return ''.join([ CSI, ';'.join(map(str, output)), letter, ]) return _sequence ansi-0.1.3/LICENSE.md0000644000076500000240000000207712551260444014637 0ustar wijnandstaff00000000000000Copyright (c) 2015 Wijnand Modderman-Lenstra Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ansi-0.1.3/PKG-INFO0000644000076500000240000000216612551260665014334 0ustar wijnandstaff00000000000000Metadata-Version: 1.0 Name: ansi Version: 0.1.3 Summary: ANSI cursor movement and graphics Home-page: https://github.com/tehmaze/ansi/ Author: Wijnand Modderman-Lenstra Author-email: maze@pyth0n.org License: UNKNOWN Description: ANSI ==== Various ANSI escape codes, used in moving the cursor in a text console or rendering coloured text. Example ------- Print something in bold yellow on a red background:: >>> from ansi.colour import fg, bg, reset >>> print map(str, [bg.red, fg.yellow, 'Hello world!', reset]) ... If you like syntactic sugar, you may also do:: >>> print bg.red(fg.yellow('Hello world!')) ... Also, 256 RGB colors are supported:: >>> from ansi.colour import rgb, reset >>> print rgb(0xff, 0x80, 0x00) + 'hello world' + reset ... If you prefer to use American English in stead:: >>> from ansi.color import ... Platform: UNKNOWN ansi-0.1.3/README0000644000076500000240000000163512551260444014112 0ustar wijnandstaff00000000000000ANSI ==== Various ANSI escape codes, used in moving the cursor in a text console or rendering coloured text. Example ------- Print something in bold yellow on a red background: >>> from ansi.colour import fg, bg >>> from ansi.colour.fx import reset >>> msg = (bg.red, fg.yellow, 'Hello world!', reset) >>> print ''.join(map(str, msg)) ... If you like syntactic sugar, you may also do: >>> from ansi.colour import fg, bg >>> print bg.red(fg.yellow('Hello world!')) ... Also, 256 RGB colours are supported: >>> from ansi.colour.rgb import rgb256 >>> from ansi.colour.fx import reset >>> msg = (rgb256(0xff, 0x80, 0x00), 'hello world', reset) >>> print ''.join(map(str, msg)) ... If you prefer to use American English instead: >>> from ansi.color import ... References ---------- http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf ansi-0.1.3/README.md0000644000076500000240000000000012551260444016740 1ansi-0.1.3/READMEustar wijnandstaff00000000000000ansi-0.1.3/setup.py0000644000076500000240000000174712551260533014747 0ustar wijnandstaff00000000000000#!/usr/bin/env python from distutils.core import setup setup(name='ansi', version='0.1.3', description='ANSI cursor movement and graphics', author='Wijnand Modderman-Lenstra', author_email='maze@pyth0n.org', url='https://github.com/tehmaze/ansi/', packages = ['ansi', 'ansi.colour'], long_description=''' ANSI ==== Various ANSI escape codes, used in moving the cursor in a text console or rendering coloured text. Example ------- Print something in bold yellow on a red background:: >>> from ansi.colour import fg, bg, reset >>> print map(str, [bg.red, fg.yellow, 'Hello world!', reset]) ... If you like syntactic sugar, you may also do:: >>> print bg.red(fg.yellow('Hello world!')) ... Also, 256 RGB colors are supported:: >>> from ansi.colour import rgb, reset >>> print rgb(0xff, 0x80, 0x00) + 'hello world' + reset ... If you prefer to use American English in stead:: >>> from ansi.color import ... ''')