On Apr 21, 2007, at 3:21 AM, Robert Rawlins - Think Blue wrote: > Chaps, > > > > Hope you’re all having a good weekend, I’m sure it’ll only be the > more ‘hard core’ of you reading this, anyone with any sanity would > be out in the sunshine right now. > > > > I’m running a program of mine from Linux bash script and it > currently outputs status messages to the command prompt, but they > all look a little boring to say the least, it’ll be like this. > > > > Application Started > > Sucess > > Application Configured > > Failed > > Retry > > Application Configured > > Success > > > > What I’d ideally like to do it give it a little bit of format, so > it perhaps looks something like this. > > > > Application > Started > [Success] > > Application > Configured > [Success] > > > > And perhaps have the word ‘success’ in green, or red for ‘failed’ > and things like that, just to make it a little more presentable to > the user. > > > > Any ideas on the best way to achieve this? > > He, he -- umm yeah (and who said all that time with THEDRAW as a kid would never pay off) ;-) Try this:
#! /usr/bin/env python def statusMessage(msg, status, msgWidth=60): if status.lower() == 'success': status = '\033[32m[%s]\033[00m' % status elif status.lower() == 'failed': status = '\033[31m[%s]\033[00m' % status else: status = '\033[33m[%s]\033[00m' % status msg = msg + ' ' * (msgWidth - len(msg)) print '%s%s' % (msg, status) if __name__ == '__main__': statusMessage('Application Started', 'Success') statusMessage('Application Configured', 'Failed') statusMessage('', 'Retry') statusMessage('Application Configured', 'Success') -- http://mail.python.org/mailman/listinfo/python-list