summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2016-02-18 09:54:37 -0800
committerJoe Anderson <jandew+dev@gmail.com>2016-02-18 09:54:37 -0800
commit1dcab572a2a4282952ed8bd48c952c7c73adf9a8 (patch)
tree8c2a6094dbfe2e11369e1d490d8158f9f52d2967
parent8d042354d445c569488eab274c4e21d745d776f0 (diff)
downloadoo-1dcab572a2a4282952ed8bd48c952c7c73adf9a8.tar.gz
oo-1dcab572a2a4282952ed8bd48c952c7c73adf9a8.zip
condense color_pair assignment
-rw-r--r--oo.py39
1 files changed, 16 insertions, 23 deletions
diff --git a/oo.py b/oo.py
index d2c96e5..9866755 100644
--- a/oo.py
+++ b/oo.py
@@ -403,29 +403,21 @@ class ooPlay:
curses.init_color(curses.COLOR_GREEN, 0, 300, 0)
curses.init_color(curses.COLOR_BLUE, 0, 0, 300)
- # TODO: try to compactify this section
- # If the first bit is on, use green background for checkering.
- curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_GREEN)
-
- # If the second bit is on, use red text for error.
- curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
- curses.init_pair(3, curses.COLOR_RED, curses.COLOR_GREEN)
-
- # If third bit is on, use blue background for cursor.
- curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLUE)
- curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLUE)
- curses.init_pair(6, curses.COLOR_RED, curses.COLOR_BLUE)
- curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLUE)
-
- # If fourth bit is on, use yellow text for fixed.
- curses.init_pair(8, curses.COLOR_YELLOW, curses.COLOR_BLACK)
- curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_GREEN)
- curses.init_pair(10, curses.COLOR_YELLOW, curses.COLOR_BLACK)
- curses.init_pair(11, curses.COLOR_YELLOW, curses.COLOR_GREEN)
- curses.init_pair(12, curses.COLOR_YELLOW, curses.COLOR_BLUE)
- curses.init_pair(13, curses.COLOR_YELLOW, curses.COLOR_BLUE)
- curses.init_pair(14, curses.COLOR_YELLOW, curses.COLOR_BLUE)
- curses.init_pair(15, curses.COLOR_YELLOW, curses.COLOR_BLUE)
+ def color_pair(n):
+ fg = curses.COLOR_WHITE
+ bg = curses.COLOR_BLACK
+ n, bit = divmod(n, 2)
+ if bit: bg = curses.COLOR_GREEN # for checkering
+ n, bit = divmod(n, 2)
+ if bit: fg = curses.COLOR_RED # for showing errors
+ n, bit = divmod(n, 2)
+ if bit: bg = curses.COLOR_BLUE # for cursor
+ n, bit = divmod(n, 2)
+ if bit: fg = curses.COLOR_YELLOW # for fixed
+ return fg, bg
+
+ for n in range(1, 2**4):
+ curses.init_pair(n, *color_pair(n))
# initialize flags
self.help_ind = 0
@@ -466,6 +458,7 @@ class ooPlay:
X = self.X
Y = self.Y - 2
self.puzzle = ooPuzzle(X, Y, toroidal = self.toroidal)
+ #TODO: this implementation of extra_hard can be really slow
if self.extra_hard:
while True:
for piece in self.puzzle.pieces.values():