Codebase list ansi / ef8dee8
Import upstream version 0.2.0+git20210110.1.d1a6feb Debian Janitor 2 years ago
11 changed file(s) with 62 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 1.0
11 Name: ansi
2 Version: 0.1.5
2 Version: 0.2.0
33 Summary: ANSI cursor movement and graphics
44 Home-page: https://github.com/tehmaze/ansi/
55 Author: Wijnand Modderman-Lenstra
+0
-41
README less more
0 ANSI
1 ====
2
3 Various ANSI escape codes, used in moving the cursor in a text console or
4 rendering coloured text.
5
6
7 Example
8 -------
9
10 Print something in bold yellow on a red background:
11
12 >>> from ansi.colour import fg, bg
13 >>> from ansi.colour.fx import reset
14 >>> msg = (bg.red, fg.yellow, 'Hello world!', reset)
15 >>> print ''.join(map(str, msg))
16 ...
17
18 If you like syntactic sugar, you may also do:
19
20 >>> from ansi.colour import fg, bg
21 >>> print bg.red(fg.yellow('Hello world!'))
22 ...
23
24 Also, 256 RGB colours are supported:
25
26 >>> from ansi.colour.rgb import rgb256
27 >>> from ansi.colour.fx import reset
28 >>> msg = (rgb256(0xff, 0x80, 0x00), 'hello world', reset)
29 >>> print ''.join(map(str, msg))
30 ...
31
32 If you prefer to use American English instead:
33
34 >>> from ansi.color import ...
35
36
37 References
38 ----------
39
40 http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
0 README.md
00 ANSI
11 ====
2
3 [![Build Status](https://travis-ci.org/tehmaze/ansi.svg?branch=master)](https://travis-ci.org/tehmaze/ansi) ![PyPI](https://img.shields.io/pypi/v/ansi)
24
35 Various ANSI escape codes, used in moving the cursor in a text console or
46 rendering coloured text.
4242 brightbrown = boldyellow # Not in ANSI/ECMA-048 standard
4343 brightgrey = boldwhite # Not in ANSI/ECMA-048 standard
4444 brightgray = boldwhite # Us English
45
46 # 8 bit and 24 bit colors colors
47 palette = lambda colour: Graphic('48;5;%s' % colour)
48 truecolor = lambda r,g,b: Graphic('48;2;%s;%s;%s' % (r,g,b))
4343 brightbrown = boldyellow # Not in ANSI/ECMA-048 standard
4444 brightgrey = boldwhite # Not in ANSI/ECMA-048 standard
4545 brightgray = boldwhite # Us English
46
47 # 8 bit and 24 bit colors colors
48 palette = lambda colour: Graphic('38;5;%s' % colour)
49 truecolor = lambda r,g,b: Graphic('38;2;%s;%s;%s' % (r,g,b))
1818 scroll_down = sequence('T')
1919 save_cursor = sequence('s')
2020 load_cursor = sequence('u')
21 show = sequence('?25h')
22 hide = sequence('?25l')
0 import binascii
1 from ansi.sequence import osc
2
3 def _b64(data):
4 if not isinstance(data, bytes):
5 data = data.encode()
6 return binascii.b2a_base64(data, newline=False).decode()
7
8 notification = osc(9)
9
10 def badge(msg):
11 return osc(1337)(SetBadgeFormat = _b64(msg))
12
13 def image(data, name="unnamed", **kwargs):
14 kwargs["inline"] = 1
15 return osc(1337)("File=name=%s" % _b64(name), **kwargs)[:-1] + ':' + _b64(data) + '\a'
16
17 def cursor(shape):
18 return osc(1337)(CursorShape=shape)
19
20 def cursorguide(on):
21 if isinstance(on, bool):
22 on = ['no','yes'][bool(on)]
23 return osc(1337)(HighlightCursorLine=on)
24
25 def attention(on):
26 if isinstance(on, bool):
27 on = ['no','yes'][bool(on)]
28 return osc(1337)(RequestAttention=on)
0 from ansi.sequence import osc
1
2 windowtitle = osc(0)
3 anchor = osc('8;')
00 CSI = '\x1b['
1 OSC = '\x1b]'
2 BEL = '\a'
13
24
35 def sequence(letter, fields=1, default=[]):
1719 ])
1820
1921 return _sequence
22
23 def osc(number):
24 def _osc(*args, **kwargs):
25 kwargs = ["%s=%s" % (k,v) for (k,v) in kwargs.items()]
26 return ''.join([
27 OSC,
28 str(number),
29 ';',
30 ';'.join(list(args)+kwargs),
31 BEL,
32 ])
33 return _osc
22 from distutils.core import setup
33
44 setup(name='ansi',
5 version='0.1.5',
5 version='0.2.0',
66 description='ANSI cursor movement and graphics',
77 author='Wijnand Modderman-Lenstra',
88 author_email='maze@pyth0n.org',