summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-06 00:36:51 +0100
committerhut <hut@lavabit.com>2010-01-06 00:36:51 +0100
commit9ec914e306514c7a6f0cf3d401e97712dc197501 (patch)
treec277809ab9c3b2e59f38b302609c7dcc10301563 /ranger
parenta78cfb7eee02d27f03b5355d9e42a6ba9522d430 (diff)
downloadranger-9ec914e306514c7a6f0cf3d401e97712dc197501.tar.gz
colorscheme: clean up
Diffstat (limited to 'ranger')
-rw-r--r--ranger/gui/colorscheme.py89
1 files changed, 56 insertions, 33 deletions
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 967a4fdd..f9fe5d90 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -1,3 +1,33 @@
+"""
+Colorschemes define colors for specific contexts.
+
+Generally, this works by passing a set of keywords (strings) to
+the colorscheme.get() method to receive the tuple (fg, bg, attr).
+fg, bg are the foreground and background colors and attr is the attribute.
+The values are specified in ranger.gui.color.
+
+A colorscheme must...
+
+1. be inside either of these directories:
+~/.ranger/colorschemes/
+path/to/ranger/colorschemes/
+
+2. be a subclass of ranger.gui.colorscheme.ColorScheme
+
+3. implement a use(self, context) method which returns (fg, bg, attr).
+context is a struct which contains all entries of CONTEXT_KEYS,
+associated with either True or False.
+
+define which colorscheme to use by having this to your options.py:
+from ranger import colorschemes
+colorscheme = colorschemes.filename
+
+If your colorscheme-file contains more than one colorscheme, specify it with:
+colorscheme = colorschemes.filename.classname
+"""
+
+from ranger.ext.openstruct import OpenStruct
+
 CONTEXT_KEYS = [ 'reset', 'error',
 		'in_browser', 'in_statusbar', 'in_titlebar', 'in_console',
 		'in_pager', 'in_taskview',
@@ -14,36 +44,25 @@ CONTEXT_KEYS = [ 'reset', 'error',
 		'title', 'text', 'highlight', 'bars', 'quotes',
 		'keybuffer']
 
-# colorscheme specification:
-#
-# A colorscheme must...
-#
-# 1. be inside either of these directories:
-# ~/.ranger/colorschemes/
-# path/to/ranger/colorschemes/
-#
-# 2. be a subclass ofranger.gui.colorscheme.ColorScheme
-# 
-# 3. have a use(self, context) method which returns a tuple of 3 integers.
-# the first integer is the foreground color, the second is the background
-# color, the third is the attribute, as specified by the curses module.
-#
-#
-# define which colorscheme to use by having this to your options.py:
-# from ranger import colorschemes
-# colorscheme = colorschemes.filename
-# 
-# If your colorscheme-file contains more than one colorscheme, specify it with:
-# colorscheme = colorschemes.filename.classname
+class ColorScheme(object):
+	"""
+	This is the class that colorschemes must inherit from.
 
-from ranger.ext.openstruct import OpenStruct
+	it defines get() 
+	it defines the get() method, which returns the color tuple
+	which fits to the given keys.
+	"""
 
-class ColorScheme(object):
 	def __init__(self):
 		self.cache = {}
 
 	def get(self, *keys):
-		"""Determine the (fg, bg, attr) tuple or get it from cache"""
+		"""
+		Returns the (fg, bg, attr) for the given keys.
+
+		Using this function rather than use() will cache all
+		colors for faster access.
+		"""
 		try:
 			return self.cache[keys]
 
@@ -59,19 +78,23 @@ class ColorScheme(object):
 			return color
 
 	def get_attr(self, *keys):
-		"""Returns the curses attr integer for the specified keys"""
+		"""
+		Returns the curses attribute for the specified keys
+		
+		Ready to use for curses.setattr()
+		"""
+		from curses import color_pair
 		from ranger.gui.color import get_color
-		import curses
 
 		fg, bg, attr = self.get(*keys)
-		return attr | curses.color_pair(get_color(fg, bg))
-
+		return attr | color_pair(get_color(fg, bg))
 
 	def use(self, context):
-		"""Use the colorscheme to determine the (fg, bg, attr) tuple.
-      This is a dummy function which always returns default_colors.
-      Override this in your custom colorscheme!
-      """
+		"""
+		Use the colorscheme to determine the (fg, bg, attr) tuple.
+		This is a dummy function which always returns default_colors.
+		Override this in your custom colorscheme!
+		"""
 		from ranger.gui.color import default_colors
-		return default_colors
 
+		return default_colors
t'>
c3ec4181 ^
d326f24d ^




1fc1d8af ^
e087f6d4
c3ec4181 ^
d326f24d ^












1fc1d8af ^


e087f6d4
533c7482 ^
d326f24d ^




1fc1d8af ^
533c7482 ^
c3ec4181 ^
d326f24d ^













1fc1d8af ^
e087f6d4
c3ec4181 ^
d326f24d ^















1fc1d8af ^

e087f6d4
c3ec4181 ^
d326f24d ^








1fc1d8af ^

e087f6d4
0cb11571 ^
d326f24d ^








1fc1d8af ^
0cb11571 ^
c3ec4181 ^
d326f24d ^









1fc1d8af ^

e087f6d4
c3ec4181 ^
d326f24d ^






1fc1d8af ^
e087f6d4
c3ec4181 ^
d326f24d ^








1fc1d8af ^

6bd78b38 ^
e47cfd56 ^
d326f24d ^

1fc1d8af ^

1d80538b ^
1fc1d8af ^



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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187