tuikit/backend_curses.py
changeset 9 7175ed629a76
parent 7 d4a291b31cbb
child 10 ec1d47e6fe09
--- a/tuikit/backend_curses.py	Wed Apr 13 13:07:26 2011 +0200
+++ b/tuikit/backend_curses.py	Sun Jul 31 13:04:39 2011 +0200
@@ -90,6 +90,7 @@
         self.colors = {}     # maps names to curses attributes
         self.colorpairs = {} # maps tuple (fg,bg) to curses color_pair
         self.colorstack = [] # pushcolor/popcolor puts or gets attributes from this
+        self.colorprefix = [] # stack of color prefixes
 
         self.inputqueue = []
         self.mbtnstack = []
@@ -174,7 +175,7 @@
         return Rect(x, y, w, h)
 
 
-    ## attributes ##
+    ## colors, attributes ##
 
     def _parsecolor(self, name):
         name = name.lower().strip()
@@ -218,6 +219,11 @@
 
 
     def pushcolor(self, name):
+        # add prefix if available
+        if len(self.colorprefix):
+            prefixname = self.colorprefix[-1] + name
+            if prefixname in self.colors:
+                name = prefixname
         attr = self.colors[name]
         self.screen.attrset(attr)
         self.colorstack.append(attr)
@@ -232,6 +238,14 @@
         self.screen.attrset(attr)
 
 
+    def pushcolorprefix(self, name):
+        self.colorprefix.append(name)
+
+
+    def popcolorprefix(self):
+        self.colorprefix.pop()
+
+
     ## drawing ##
 
     def putch(self, x, y, c):