From 9c3472a73727c28f3920ea950690f6275549eef6 Mon Sep 17 00:00:00 2001 From: C. Scott Ananian Date: Tue, 11 Dec 2007 19:35:21 +0000 Subject: Add text-color functions to console library; use them in 'jump' example. --- (limited to 'library') diff --git a/library/pippy/console.py b/library/pippy/console.py index cdbb023..1a00c89 100644 --- a/library/pippy/console.py +++ b/library/pippy/console.py @@ -1,5 +1,53 @@ """Console helpers for pippy.""" +import sys def clear(): """Clear screen on console.""" # magic escape sequence - print '\x1B[H\x1B[J' # clear screen + sys.stdout.write('\x1B[H\x1B[J') + +def red(): + """Change text color to red.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;31m') + +def green(): + """Change text color to green.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;32m') + +def orange(): + """Change text color to orange.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;33m') + +def blue(): + """Change text color to blue.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;34m') + +def purple(): + """Change text color to purple.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;35m') + +def cyan(): + """Change text color to cyan.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;36m') + +def grey(): + """Change text color to grey.""" + # magic escape sequence. + sys.stdout.write('\x1B[0;37m') +gray=grey + +def black(): + """Change text color to blue.""" + # magic escape sequence. + # ;38m seems to be identical to this one. + sys.stdout.write('\x1B[0;39m') + +def reset(): + """Clear screen and reset text color to black.""" + clear() + black() -- cgit v0.9.1