print color strings?
Michael Hudson
Michael.Hudson at p98.f112.n480.z2.fidonet.org
Thu Jul 1 21:17:47 EDT 1999
More information about the Python-list mailing list
Thu Jul 1 21:17:47 EDT 1999
- Previous message (by thread): print color strings?
- Next message (by thread): print color strings?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: Michael Hudson <mwh21 at cam.ac.uk> Gerrit Holl <gerrit.holl at pobox.com> writes: > Hello, > > is there an easy way to print color strings in python? > > A function like printcolor('brightyellow', 'red', 'spam'), that finds > out on what kind of terminal you are and prints it to stdout? That sort of finding out is what terminfo is for; there's no Python interface that I know of (such a beast shouldn't be too hard to write, but a bit pointless, I suspect). However there is the `tput' program; os.system("tput setaf 1") should turn your foreground colour red. Read the terminfo man pages for more codes. You'd probably want to cache the escape codes rather than spinning a new process each time you need one. codes['redf'] = os.popen("tput setaf 1").read() codes['redb'] = os.popen("tput setab 1").read() codes['greenf']=os.popen("tput setaf 2").read() ... and so on. I'm certainly not an expert on such matters; reading man pages for tput, terminfo and term and playing around will get you exactly where I've got to. All terribly unix-centric, of course. HTH Michael
- Previous message (by thread): print color strings?
- Next message (by thread): print color strings?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list