From: Oleg Broytman Date: Fri, 17 Jan 2014 22:25:29 +0000 (+0400) Subject: Refactor loop X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=dc16915c13154ea56c4700c3cf2366788e202bd9;p=dotfiles.git Refactor loop --- diff --git a/lib/python/init.py b/lib/python/init.py index 26692bb..d835c1c 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -59,40 +59,42 @@ def init(): # From Randall Hopper - if _term in term: - if background == 'dark': - ps1_color = '3' # yellow - stdout_color = '7' # bold white - else: - ps1_color = '4' # blue - stdout_color = '0' # bold black for _term in ['linux', 'rxvt', 'screen', 'term', 'vt100']: + if _term not in term: + continue + + if background == 'dark': + ps1_color = '3' # yellow + stdout_color = '7' # bold white + else: + ps1_color = '4' # blue + stdout_color = '0' # bold black - sys.ps1 = '\001\033[3%sm\002>>>\001\033[0m\002 ' % ps1_color - sys.ps2 = '\001\033[1;32m\002...\001\033[0m\002 ' # bold green + sys.ps1 = '\001\033[3%sm\002>>>\001\033[0m\002 ' % ps1_color + sys.ps2 = '\001\033[1;32m\002...\001\033[0m\002 ' # bold green - # From Denis Otkidach + # From Denis Otkidach - class ColoredFile: - def __init__(self, fp, begin, end='\033[0m'): # reset all attributes - self.__fp = fp - self.__begin = begin - self.__end = end + class ColoredFile: + def __init__(self, fp, begin, end='\033[0m'): # reset all attributes + self.__fp = fp + self.__begin = begin + self.__end = end - def write(self, s): - self.__fp.write(self.__begin+s+self.__end) + def write(self, s): + self.__fp.write(self.__begin+s+self.__end) - def writelines(self, lines): - map(self.write, lines) + def writelines(self, lines): + map(self.write, lines) - def __getattr__(self, attr): - return getattr(self.__fp, attr) + def __getattr__(self, attr): + return getattr(self.__fp, attr) - sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color) - sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red + sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color) + sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red - break + break try: import locale