Import upstream version 0.2.0+git20210110.1.d1a6feb
Debian Janitor
2 years ago
0 | 0 |
Metadata-Version: 1.0
|
1 | 1 |
Name: ansi
|
2 | |
Version: 0.1.5
|
|
2 |
Version: 0.2.0
|
3 | 3 |
Summary: ANSI cursor movement and graphics
|
4 | 4 |
Home-page: https://github.com/tehmaze/ansi/
|
5 | 5 |
Author: Wijnand Modderman-Lenstra
|
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 | 0 |
ANSI
|
1 | 1 |
====
|
|
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)
|
2 | 4 |
|
3 | 5 |
Various ANSI escape codes, used in moving the cursor in a text console or
|
4 | 6 |
rendering coloured text.
|
42 | 42 |
brightbrown = boldyellow # Not in ANSI/ECMA-048 standard
|
43 | 43 |
brightgrey = boldwhite # Not in ANSI/ECMA-048 standard
|
44 | 44 |
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))
|
43 | 43 |
brightbrown = boldyellow # Not in ANSI/ECMA-048 standard
|
44 | 44 |
brightgrey = boldwhite # Not in ANSI/ECMA-048 standard
|
45 | 45 |
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))
|
18 | 18 |
scroll_down = sequence('T')
|
19 | 19 |
save_cursor = sequence('s')
|
20 | 20 |
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;')
|
0 | 0 |
CSI = '\x1b['
|
|
1 |
OSC = '\x1b]'
|
|
2 |
BEL = '\a'
|
1 | 3 |
|
2 | 4 |
|
3 | 5 |
def sequence(letter, fields=1, default=[]):
|
|
17 | 19 |
])
|
18 | 20 |
|
19 | 21 |
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
|
2 | 2 |
from distutils.core import setup
|
3 | 3 |
|
4 | 4 |
setup(name='ansi',
|
5 | |
version='0.1.5',
|
|
5 |
version='0.2.0',
|
6 | 6 |
description='ANSI cursor movement and graphics',
|
7 | 7 |
author='Wijnand Modderman-Lenstra',
|
8 | 8 |
author_email='maze@pyth0n.org',
|