abstract

Secondary abstractions for terminal control

The code here is mostly a front-end to the control module. The OutputStream class acts as a wrapper for tty pseudo files like sys.stdout and sys.stder and can handle several ANSI control codes on multiple platforms.

Here is an example usage.

import os

stdout.write('spam' +

    
color('bright','yellow','white') +

    
'eggs' +

    
color('default') + os.linesep

)

Warning: on IPython setting sys.stdout to the stdout object in this module will break readline.


Attributes

a stdout

<terminate.abstract.OutputStream object at 0xb756692c>

a stderr

<terminate.abstract.OutputStream object at 0xb756694c>

Functions

f color(codes=[], fg=None, bg=None) ...

Returns an ANSI control code. This is useful when writing to an OutputStream.

codes
A list containing strings. The strings should one of the keys in the DISPLAY_CODES constant in the control module. It can also be just a single string.
fg, bg
A string. Explicitly for setting the foreground or background. Use one of the keys in the COLORS constant in the control module.
color(('bright','underline'),'blue','white')
give bright blue foreground and white background with underline
color(fg='blue')
gives a blue foreground
color('default')
resets the color to the default.

Avoid using black or white. Depending on the situation the default background/foreground is normally black or white, but it's hard to tell which. Bare terminals are normally white on black, but virtual terminals run from X or another GUI system are often black on white. This can lead to unpredicatble results. If you want reversed colours, use the 'reverse' code, and if you want to set the colors back to their original colors, use the 'default' code.

Also, be prudent with your use of 'hidden' and 'blink'. Several terminals do not support them (and for good reason too), they can be really annoying and make reading difficult.

Classes

C OutputStream(...) ...

This class contains 21 members.

See the source for more information.