wie setze ich farben beim output?

Ja, ich habe genau das gleiche Problem. Nun, mangels Besseren, habe ich eine Klasse zusammengebastelt, die allerdings mit Bash-Codes arbeitet. Aufbauende Kritik oder Verbesserungsvorschlaege sind willkommen. Gruss Lajos P.S. Diese ist meine erste Klasse. class Cline: ''' The class ``Cline'' enables the printing of a text on the terminal in color. Usage: from cline import * myline='This text is current.<0;32>This is green.<0;31>This is red.<0;00>This is current.' coloredLine=Cline() coloredLine.write(myline) The tags contain the bash color codes. These are: Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37 reset 0;00 The trailing text will be colored according to the leading tag until an other tag or end of line occurs. This class uses the color capabilities of Bash, because I could not figure out how to solve it just in Python. Author: Kuljo Version: 0.3.0 Date: 2006-03-16 License: GPL ''' def write(self, text): import os line='' currentCursor=0 oldCursor=0 text=text+'<0;00>' while 0 == 0: # endless loop currentCursor=text.find('<', oldCursor) if currentCursor == -1: # if end of text exeeded break if (text[currentCursor+2:currentCursor+3] == ';' and text[currentCursor+5:currentCursor+6] == '>'): # if just a gt in text colorCode=text[oldCursor-5:oldCursor-1] line=line+text[oldCursor:currentCursor] oldCursor=currentCursor+6 exec('''os.system("echo -en '\E[;'''+colorCode+'m'+line+'\'")') os.system("tput sgr0") ##reset terminal color line='' print '' _________________________________________________________________________ Társasházi gyakorlati kézikönyv - Hasznos és nélkülözhetetlen segítője minden társasházban lakónak: http://manager.menedzsmentforum.hu/tarsashaz/ _______________________________________________ python-de maillist - python-de@python.net http://python.net/mailman/listinfo/python-de
participants (1)
-
Lajos Kuljo