summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parentd194334e1653c352c734299f50abeee9a77dca24 (diff)
downloadranger-e94916a912655c055f1d45a92c6f178f7742873f.tar.gz
gui.color: deal with terminals without "default" color
Diffstat (limited to 'ranger')
-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))
8a9a6522a605acd434059582bfc'>577248f ^
f37508a ^
577248f ^

5d0402a ^


753adb9 ^
5d0402a ^

fa04a1e ^
10dd23f ^


8126d82 ^





2a09617 ^


































f42724c ^


74af57b ^
f42724c ^

aeb7005
74af57b ^















648ca98 ^



a21afda ^




1767e4f ^
a21afda ^

f42724c ^
a0be5e8 ^
b275a39 ^

39c93d2 ^
60b351b ^
f406bf5 ^



2a09617 ^
b60999c ^
2a09617 ^



b60999c ^
f406bf5 ^
77a0f68 ^


1418e1b ^
60b351b ^
de122b1 ^
a15ea01 ^


1418e1b ^
661e3ec ^

305446a ^
6394e38 ^
aeb7005
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156