Treat strings like Items on a 2D Canvas.
Project description
Treat Strings like Items on a 2D Canvas
With this primitive library you can do things like this:
from ascii_canvas import canvas
from ascii_canvas import item
canvas_ = canvas.Canvas()
rect_a = item.Item('+-----+\n|Hello|\n+-----+', position=[0, 0])
rect_b = item.Item('+-----+\n|World|\n+-----+', position=[16, 5])
rect_c = item.Item('+-+\n|!|\n+-+', position=[32, 0])
line_a = item.Line(start=[7, 1], end=[15, 6])
line_b = item.Line(start=[23, 6], end=[31, 1])
canvas_.add_item(rect_a)
canvas_.add_item(rect_b)
canvas_.add_item(rect_c)
canvas_.add_item(line_a)
canvas_.add_item(line_b)
print(canvas_.draw())
Which results in this output:
+-----+ +-+
|Hello|----+ +----|!|
+-----+ | | +-+
| |
| |
| +-----+ |
+----|World|----+
+-----+
Type hints
The library contains Python3.6-style type hints. For lower Python versions the hints are however stripped on the fly with strip-hints!, making ascii-canvas compatible all the way down to Python 2.6. Please note that in Python < 3.6 you can NOT import the classes directly due to the stripping of the type hints, so stick with the way that the example imports the module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ascii-canvas-1.3.3.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for ascii_canvas-1.3.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62eb54d9d482bb0f56165270d40b5a095f3c996b8c6b2ddf4a83164a6756ecc3 |
|
MD5 | 02b3c9462dfe71848b6f101776f2d31c |
|
BLAKE2b-256 | 2a63502078a4138c3fa2b21a340056de3282c0b0d3f40ea202684fab06551606 |