Package ivs :: Package aux :: Module termtools
[hide private]
[frames] | no frames]

Module termtools

source code

Tools for cursor and color control in the terminal

Example usage (this does not work in the documentation):

>>> print green('this text is green')
this text is green
>>> print blink('this text blinks')+' this text does not blink'
this text blinks this text does not blink

You can combine all the possibilities, as the functions are generated on the fly:

>>> print blink_green_bgred_bold('blinking green bold text on red background')
blinking green bold text on red background
Classes [hide private]
  CallInstruct
Generate a callable function on-the-fly.
  MemoryMonitor
  Wrapper
Wrap the module so that the getattr function can be redefined.
Functions [hide private]
 
overwrite_line(message)
Save cursor at current position, clear current line, print the message and reset the cursor.
source code
 
line_at_a_time(fileobj)
Return one line at a time from a file-like object.
source code
 
subprocess_timeout(command, time_out)
Kill a running subprocess after a certain amount of time.
source code
Variables [hide private]
  RED = "\[\033[0;35m\]"
  YELLOW = "\[\033[0;33m\]"
  instructs = {'black': "\033[30m", 'red': "\033[31m", 'green': ...
Function Details [hide private]

overwrite_line(message)

source code 

Save cursor at current position, clear current line, print the message and reset the cursor.

Parameters:
  • message (str) - message to print to the screen

line_at_a_time(fileobj)

source code 

Return one line at a time from a file-like object.

>>> #p1 = subprocess.Popen('ls',shell=True,stdout=subprocess.PIPE)
>>> #for line in line_at_a_time(p1.stdout):
... #    print 'next line:',line.strip()
>>> #retcode = p1.wait()

use os.kill(p1.pid,SIGKILL) to with SIGKILL from signal standard module to kill the process.

return model_number Works around the iter behavior of pipe files in Python 2.x, e.g., instead of "for line in file" you can write "for line in line_at_a_time(file)"

subprocess_timeout(command, time_out)

source code 

Kill a running subprocess after a certain amount of time.

Command represents the command for the process you would give in a terminal e.g. 'ls -l' in a terminal becomes ["ls", "-l"] or 'firefox' becomes ["firefox"]'; time_out is expressed in seconds. If the process did not complete before time_out, the process is killed.

Parameters:
  • command (str) - command to run

Variables Details [hide private]

instructs

Value:
{'black': "\033[30m", 'red': "\033[31m", 'green': "\033[32m", 'yellow'\
: "\033[33m", 'blue': "\033[34m", 'magenta': "\033[35m", 'cyan': "\033\
[36m", 'white': "\033[37m", 'bgblack': "\033[40m", 'bgred': "\033[41m"\
, 'bggreen': "\033[42m", 'bgyellow': "\033[43m", 'bgblue': "\033[44m",\
 'bgmagenta': "\033[45m", 'bgcyan': "\033[46m", 'bgwhite': "\033[47m",\
 'blink': '\033[5m', 'underline': '\033[4m', 'bold': '\033[1m', 'reset\
': '\033[m'}