summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2013-11-11 22:03:37 +0100
committerhut <hut@lepus.uberspace.de>2013-11-11 22:03:37 +0100
commite94916a912655c055f1d45a92c6f178f7742873f (patch)
tree706a96c5289d9308df95e4fac89bad29175290e7
parentd194334e1653c352c734299f50abeee9a77dca24 (diff)
downloadranger-e94916a912655c055f1d45a92c6f178f7742873f.tar.gz
gui.color: deal with terminals without "default" color
-rw-r--r--ranger/gui/color.py14
-rw-r--r--ranger/gui/ui.py5
2 files changed, 17 insertions, 2 deletions
diff --git a/ranger/gui/color.py b/ranger/gui/color.py
index 991943b6..d64b5b40 100644
--- a/ranger/gui/color.py
+++ b/ranger/gui/color.py
@@ -15,6 +15,8 @@ bool(attr & reverse) # => False
 
 import curses
 
+DEFAULT_FOREGROUND = curses.COLOR_WHITE
+DEFAULT_BACKGROUND = curses.COLOR_BLACK
 COLOR_PAIRS = {10: 0}
 
 def get_color(fg, bg):
@@ -23,7 +25,17 @@ def get_color(fg, bg):
     key = (fg, bg)
     if key not in COLOR_PAIRS:
         size = len(COLOR_PAIRS)
-        curses.init_pair(size, fg, bg)
+        try:
+            curses.init_pair(size, fg, bg)
+        except:
+            # If curses.use_default_colors() failed during the initialization
+            # of curses, then using -1 as fg or bg will fail as well, which
+            # we need to handle with fallback-defaults:
+            if fg == -1:  # -1 is the "default" color
+                fg = DEFAULT_FOREGROUND
+            if bg == -1:  # -1 is the "default" color
+                bg = DEFAULT_BACKGROUND
+            curses.init_pair(size, fg, bg)
         COLOR_PAIRS[key] = size
 
     return COLOR_PAIRS[key]
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 3aeeb4fe..1f95ac59 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -71,7 +71,10 @@ class UI(DisplayableContainer):
         except:
             pass
         curses.start_color()
-        curses.use_default_colors()
+        try:
+            curses.use_default_colors()
+        except:
+            pass
 
         self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
         _setup_mouse(dict(value=self.settings.mouse_enabled))