Next: Languages, Previous: Printing in TTY with KMS, Up: Inner workings [Contents][Index]
Ponysay supports three type of output truncations, cutting away overflow on the right and truncation the height by either keeping the bottom or keeping the top. By default the latest is enabled under TTY, cutting away overflow on the right is always enabled by default.
Truncating the height in TTY is required under Kernel Mode Setting (KMS) support to
keep the colours from being messed up when the ponies is moved in the screen during
print. Prior to version 2.0 this was done either by piping to head
(keeps
the top) or by piping to tail
(keeps the bottom.) head
and
tail
takes as argument the number of lines to keep at most.
The size of the terminal, measured in characters, is fetched from stty size
,
which returns HEIGHT WIDTH
, and cut
it the used to get either the
height or the width. This requires only GNU Coreutils; earlier tput rows
and
tput cols
were used, this however required, the only de facto standard,
package ncurses
, some shells have environment variables for this.
Since version 2.1 truncation is done internally in the Python script, before that it
was done in a custom C program truncater
, that was installed to
/usr/lib/ponysay/truncater. It recognised UTF-8 ANSI escape sequences,
including OSI P and CSI m, which is essential for the truncation to be correct. It
also expands tabs to every eighth column and resets the background colour when needed,
and writes ANSI escape sequences that are on the left side of the truncation. The
truncater stops CSI sequences on the first ASCII letter ([a-zA-Z]
), but also
stops escape sequences after the first character after the initial escape if it is
not either [
(CSI) or ]
(OSI). In the previous, C, program it supported
UTF-8 by assuming that bytes do not match 10xxxxxx
and only those bytes were
visible. This now fixed internally in Python, but has also been improved to exclude
combining characters from the set of visible characters. Another difference is that
the background colours are not reset, instead ANSI colours after the truncation point
are still printed.
Next: Languages, Previous: Printing in TTY with KMS, Up: Inner workings [Contents][Index]