Skip to content
Browse files

More sensible shell coloring

  • Loading branch information...
1 parent a2d8ab7 commit e096eb23ee032d86993fbf0be2f428e485d12e67 @mattbasta mattbasta committed Jan 14, 2013
Showing with 5 additions and 7 deletions.
  1. +5 −7 validator/outputhandlers/shellcolors.py
View
12 validator/outputhandlers/shellcolors.py
@@ -32,8 +32,7 @@ def __init__(self, buffer=sys.stdout, no_color=False):
# Initialize a store for the colors and pre-populate it
# with the un-color color.
- self.colors = {}
- self.colors["NORMAL"] = curses.tigetstr("sgr0") or ''
+ self.colors = {"NORMAL": curses.tigetstr("sgr0") or ''}
# Determines capabilities of the terminal.
fgColorSeq = curses.tigetstr('setaf') or \
@@ -62,15 +61,14 @@ def colorize_text(self, text):
rany = text.rfind("<<")
# Put in the escape sequences.
- text = text.replace("%", "%%")
- text = text.replace("<<", "%(").replace(">>", ")s")
+ for color, code in self.colors.items():
+ text = text.replace("<<%s>>" % color, code)
# Make sure that the last sequence is a NORMAL sequence.
if rany > -1 and rnormal < rany:
- text += "%(NORMAL)s"
+ text += self.colors["NORMAL"]
- # Replace our placeholders with the physical sequence data.
- return text % self.colors
+ return text
def write(self, text):
"Uses curses to print in the fanciest way possible."

0 comments on commit e096eb2

Please sign in to comment.
Something went wrong with that request. Please try again.