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
outta-0.3.1.tar.gz
(10.8 kB
view hashes)
Built Distribution
outta-0.3.1-py3-none-any.whl
(11.1 kB
view hashes)