I've written a Python module to dump objects. When using it with objects that hold binary data (e.g.
numpy.ndarray) in a
linux terminal (
TERM=linux) though, printing out the data results in the terminal's font breaking - apparently, some characters are treated as terminal control sequences. In Windows, printing works fine, even in Cygwin's
mintty terminal (it has
The same happens when I
cat a binary file.
I can fix that with
reset, of course, but at the cost of losing the output, and it's generally inconvenient. While I do know that most, if not all control characters have alternative graphical representations in fonts (e.g. for
So, is there some way to alter the raw stream to make the
linux terminal treat special characters that were in it like literals? Basically, I wish to see something like this:
I'm primarily interested in a programmatic way (=what needs to be done from terminal's standpoint and an implementation in common system libraries if there is one); a way in shell would be a plus.
repr() doesn't fit my needs: it expands any non-printable-ASCII characters and into variable-length sequences, including national letters, while the module's design goal is for the dump printout to be concise and readable.