ANSI control code parsing
Project description
A tool for parsing terminal control codes and escape sequences from a stream of text.
Outta was born out of a need to learn more about the control codes sent from terminal programs to the terminals that host them. The Parser class can parse a stream of text and produce a sequence of Elements that tell you what codes (and regular text) were in it.
Here’s a quick example:
from outta.parser import Parser
# Here's the text to be parsed
text = "\x1b[4COut of\x1b[3Dta control!"
# Construct a Parser and feed the text in.
parser = Parser()
elements = tuple(parser.feed(text))
# Print each of the elements
for element in elements:
print(">", element)
# Reconstruct the input text from the elements and print it
full_text = "".join(e.text for e in elements)
assert full_text == text
print(full_text)
and here’s how that look if you run it:
% python docs/example.py
> CursorForward(parameters=(4,), keywords={}, text='\x1b[4C')
> Out of
> CursorBack(parameters=(3,), keywords={}, text='\x1b[3D')
> ta control!
Outta control!
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file outta-0.3.1.tar.gz.
File metadata
- Download URL: outta-0.3.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3be11bd2aa81d54db753c969fccf7043463626ff5ca6ad62598b0d42b622f01
|
|
| MD5 |
0fe132bd6033f5c96cfd6a099cf4e86e
|
|
| BLAKE2b-256 |
9f0ab1830365d0d5525d75742b76408a26c304b5ba702fed87461c551b1d319c
|
File details
Details for the file outta-0.3.1-py3-none-any.whl.
File metadata
- Download URL: outta-0.3.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99821716f438e544f5e6655b933643aca570963b50571de9f1ce057b696ce43
|
|
| MD5 |
5533c21d2abdfd62590ba085350f08c4
|
|
| BLAKE2b-256 |
49a834aeaddbc389a6af2ea1bf1775b565dfda27d2cb7c5a0066a885d502ab04
|