about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-03 20:25:01 +0100
committerhut <hut@lavabit.com>2009-12-03 20:25:01 +0100
commitb810fe28876d750495ac05d9993ce02afb561c01 (patch)
tree8efbd9f7b4a0f795b7926ccaaa2ce870df4b4bed
parent4cb54d3819d8a58d0bd07b8da0c4a978807c44ec (diff)
downloadranger-b810fe28876d750495ac05d9993ce02afb561c01.tar.gz
mime type support, integrated into colorschemes
-rw-r--r--ranger/conf/colorschemes/snow.py16
-rw-r--r--ranger/fsobject.py35
-rw-r--r--ranger/gui/colorscheme.py1
-rw-r--r--ranger/gui/wdisplay.py2
-rw-r--r--ranger/mimetype.py14
5 files changed, 62 insertions, 6 deletions
diff --git a/ranger/conf/colorschemes/snow.py b/ranger/conf/colorschemes/snow.py
index 4bb00ca9..d5bd8c3a 100644
--- a/ranger/conf/colorschemes/snow.py
+++ b/ranger/conf/colorschemes/snow.py
@@ -17,14 +17,24 @@ class MyColorScheme(ColorScheme):
 			if context.empty or context.error:
 				bg = red
 
+			if context.media:
+				if context.image:
+					fg = yellow
+				else:
+					fg = magenta
+
+			if context.container:
+				fg = red
+
+			if context.document:
+				fg = default
+
 			if context.directory:
 				fg = blue
 			elif context.executable:
+				attr |= bold
 				fg = green
 
-			if context.media:
-				fg = magenta
-
 			if context.link:
 				fg = cyan
 
diff --git a/ranger/fsobject.py b/ranger/fsobject.py
index c4a1e882..35a6465a 100644
--- a/ranger/fsobject.py
+++ b/ranger/fsobject.py
@@ -8,6 +8,10 @@ T_NONEXISTANT = 'nonexistant'
 
 BAD_INFO = None
 
+CONTAINER_EXTENSIONS = 'rar zip tar gz bz bz2 tgz 7z iso cab'.split()
+DOCUMENT_EXTENSIONS = 'pdf doc ppt odt'.split()
+DOCUMENT_BASENAMES = 'README TODO LICENSE'.split()
+
 class FileSystemObject(object):
 
 	def __init__(self, path):
@@ -19,6 +23,10 @@ class FileSystemObject(object):
 		self.path = path
 		self.basename = basename(path)
 		self.dirname = dirname(path)
+		try:
+			self.extension = self.basename[self.basename.rindex('.') + 1:]
+		except ValueError:
+			self.extension = None
 		self.exists = False
 		self.accessible = False
 		self.marked = False
@@ -32,17 +40,40 @@ class FileSystemObject(object):
 		self.infostring = None
 		self.permissions = None
 		self.type = T_UNKNOWN
+
+		self.set_mimetype()
 	
 	def __str__(self):
 		return str(self.path)
 
+	def set_mimetype(self):
+		import ranger.mimetype as mimetype
+		try:
+			self.mimetype = mimetype.get() [self.extension]
+		except KeyError:
+			self.mimetype = ''
+
+		self.video = self.mimetype.startswith('video')
+		self.image = self.mimetype.startswith('image')
+		self.audio = self.mimetype.startswith('audio')
+		self.media = self.video or self.image or self.audio
+		self.document = self.mimetype.startswith('text') or (self.extension in DOCUMENT_EXTENSIONS) or (self.basename in DOCUMENT_BASENAMES)
+		self.container = self.extension in CONTAINER_EXTENSIONS
+
+		keys = ('video', 'audio', 'image', 'media', 'document', 'container')
+		self.mimetype_tuple = tuple(key for key in keys if getattr(self, key))
+
+		if self.mimetype == '':
+			self.mimetype = None
+
 	# load() reads useful information about the file from the file system
 	# and caches it in instance attributes.
 	def load(self):
-		self.loaded = True
-
 		import os
 		from ranger.helper import human_readable
+
+		self.loaded = True
+
 		if os.access(self.path, os.F_OK):
 			self.stat = os.stat(self.path)
 			self.islink = os.path.islink(self.path)
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 282a08ba..d7833016 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -2,6 +2,7 @@ CONTEXT_KEYS = [ 'reset', 'error',
 		'in_display', 'in_statusbar', 'in_titlebar', 'in_console',
 		'directory', 'file', 'hostname',
 		'executable', 'media', 'link',
+		'video', 'audio', 'image', 'media', 'document', 'container',
 		'broken', 'selected', 'empty', 'maindisplay']
 
 class ColorSchemeContext():
diff --git a/ranger/gui/wdisplay.py b/ranger/gui/wdisplay.py
index a1953001..07111437 100644
--- a/ranger/gui/wdisplay.py
+++ b/ranger/gui/wdisplay.py
@@ -107,7 +107,7 @@ class WDisplay(SuperClass):
 			except IndexError:
 				break
 
-			this_color = base_color[:]
+			this_color = base_color + list(drawed.mimetype_tuple)
 
 			if i == selected_i:
 				this_color.append('selected')
diff --git a/ranger/mimetype.py b/ranger/mimetype.py
new file mode 100644
index 00000000..4346d9c8
--- /dev/null
+++ b/ranger/mimetype.py
@@ -0,0 +1,14 @@
+types = {'not loaded': True}
+
+def load():
+	import sys, os, pickle
+	types.clear()
+
+	f = open(os.path.join(sys.path[0], 'data/mime.dat'), 'rb')
+	types.update(pickle.load(f))
+	f.close()
+
+def get():
+	if 'not loaded' in types:
+		load()
+	return types
^
c062697c ^
decaddb4 ^

e853b94e ^
7da71d03 ^
decaddb4 ^



c062697c ^

c82d0176 ^
c062697c ^



e853b94e ^
7da71d03 ^
c062697c ^





c82d0176 ^
c062697c ^



e853b94e ^
7da71d03 ^
c062697c ^



32f6079f ^

c82d0176 ^
32f6079f ^



e853b94e ^
7da71d03 ^
32f6079f ^




9ea76483 ^
32f6079f ^
c82d0176 ^
32f6079f ^



e853b94e ^
7da71d03 ^
32f6079f ^



decaddb4 ^








7ac221e4 ^
decaddb4 ^
7ac221e4 ^
decaddb4 ^
7ac221e4 ^
decaddb4 ^


15ab959d ^

9ea76483 ^
15ab959d ^
9ea76483 ^
15ab959d ^
9ea76483 ^
15ab959d ^

1848b18f ^









9ea76483 ^

9ea76483 ^
9ea76483 ^
9ea76483 ^
9ea76483 ^
9ea76483 ^
9ea76483 ^
decaddb4 ^













3d45bf38 ^












































c062697c ^






























































3ba63579 ^
c062697c ^

3ba63579 ^
32f6079f ^





























15ab959d ^


































9cc16d04 ^
15ab959d ^






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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387