Manipulate ASCII Art & Tables in a bitmap-image-like manner.
Project description
ASCIM - Manipulate ASCII art as you would do with raster images
Pre-document Humor
Do you know why the crazy guy started a side project to feed another one?
No, you should ASCIM.
If you came here from memethesis-cli, go straight to section 'ASCIM Tables'.
Installation
pip install ascim
will do.
Usage
Basic ASCIM Class
from ascim.ascim import ASCIM
im = ASCIM('''In ASCIM,
every character
is like
a pixel''')
im
is now an ASCIM object, with the following text (enclosed in rectangle*):
+-----------------+
0| In ASCIM, |
1| every character |
2| is like |
3| a pixel |
+-----------------+
Lines 0, 2, and 3, which are zero-indexed, are padded with spaces to their right so that they are all uniform in length with Line 1. An ASCIM object is treated as an image, so string methods no longer apply.
* but what is in this rectangle? We will cover this later on in section 'ASCIM Tables'.
ASCIM Tables
An ASCIM Table is a container object of ASCIM Images. An ASCIM Image (or NoneType) can take up one cell in a table, just like in spreadsheets.
Code example:
from ascim.ascim import ASCIM
from ascim.table import ASCIMTable
table = ASCIMTable.from_text('<copy paste that table from below>')
print(table.cell_at(0, 0).to_text()) # => 'symbol'
print(table.size) # => (4, 7)
Textual representation
The textual representation for ASCIM Tables are designed to be both machine- and human-readable. Here is an example: (relevant xkcd)
+--------+---------------+---------------+------------------------+
| symbol | name | size | notes |
+--------+---------------+---------------+------------------------+
| kB | Kilobyte | 1024 bytes | 1000 bytes during leap |
| | | or 1000 bytes | years, 1024 otherwise |
+--------+---------------+---------------+------------------------+
| KB | Kelly-Bootle | 1012 bytes | Compromise between |
| | Standard Unit | | 1000 and 1024 bytes |
+--------+---------------+---------------+------------------------+
| KiB | Imaginary | 1024sqrt(-1) | Used in quantum |
| | Kilobyte | bytes | computing |
+--------+---------------+---------------+------------------------+
| kb | Intel | 1023.937528 | Calculated on |
| | Kilobyte | bytes | Pentium F.P.U |
+--------+---------------+---------------+------------------------+
| Kb | Drivemaker's | Currently | Shrinksby 4 bytes each |
| | Kilobyte | 908 bytes | year for marketing |
| | | | reasons |
+--------+---------------+---------------+------------------------+
| KBa | Baker's | 1152 Bytes | 9 bits to the byte |
| | Kilobyte | | since you're such a |
| | | | good customer |
+--------+---------------+---------------+------------------------+
Specification
-
A cell is an ASCIM object or NoneType stored in the ASCIMTable. When printed, it is enclosed with
+
and-
horizontally and+
and|
vertically. NoneType denotes there is no content in the cell, and is interpreted as an 1x1 ASCIM object when displayed. -
On each side of the pipe (vertical bar;
|
) that is a cell MUST be a space. As illustrated:+---+ |012| |345| |678| +---+
In this rect-enclosed area, the "cell" only covers 1, 4, and 7. Locations 0, 3, 6, 2, 5, 8 MUST be a space. Locations 1 and 7 SHOULD NOT be a space. That said, only horizontal margins are necessary.
-
When a row is too wide or a column is too tall in the text to convert to an ASCIMTable, the excess columns/rows of spaces are cut off.
ASCIM Draw
With ASCIMDraw you can make in-place modifications with an ASCIM Image. An ASCIMDraw object takes a (reference to) an ASCIM object as its argument.
Code example:
from ascim.ascim import ASCIM
from ascim.draw import ASCIMDraw
im = ASCIM.new((5, 5))
draw = ASCIMDraw(im)
draw.text((1, 2, 4, 2), 'oh nice') # text is wrapped in a 4x2 box
# `im` is modified in-place
print(im.to_text())
#
#
# oh
# nice
#
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
Built Distribution
File details
Details for the file ascim-0.1.1.tar.gz
.
File metadata
- Download URL: ascim-0.1.1.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3447cf7be4fe1a4807fbb72f3b950c93a9f03ba448555480c5b8f0d70f13726a |
|
MD5 | 6fc072d98b8deb096165c1b778961e50 |
|
BLAKE2b-256 | 19bf047f3682a7046ccb5d227edcda3c7164e5df650d3793f9d0a4372435fc14 |
File details
Details for the file ascim-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: ascim-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f8aef1e84c96cf01a64dd4875d5fb796e0d0282d90e6272c1a38179b7b20b86 |
|
MD5 | 620e2b36e53068b027bcc63b8092029f |
|
BLAKE2b-256 | 7e263c7f468e1ea55d80d515ff8971aeeca670812cfd97d94b4f78ad046304ef |