about summary refs log tree commit diff stats
path: root/subx/apps/crenshaw2-1b
Commit message (Expand)AuthorAgeFilesLines
* 5460Kartik Agaram2019-07-241-0/+0
* 5454Kartik Agaram2019-07-221-0/+0
* 5438 - raise error on uppercase hexKartik Agaram2019-07-211-0/+0
* 5437Kartik Agaram2019-07-211-0/+0
* 5429Kartik Agaram2019-07-201-0/+0
* 5408Kartik Agaram2019-07-161-0/+0
* zero out new rows returned by get-or-insertKartik Agaram2019-07-101-0/+0
* .Kartik Agaram2019-07-081-0/+0
* move `is-label?` to `subx-common`Kartik Agaram2019-07-071-0/+0
* Merge branch 'master' into surveyKartik Agaram2019-07-031-0/+0
|\
| * 5218Kartik Agaram2019-05-221-0/+0
* | some primitives for emitting tracesKartik Agaram2019-07-011-0/+0
* | .Kartik Agaram2019-07-011-0/+0
* | unsigned comparison for addresses in more placesKartik Agaram2019-07-011-0/+0
* | .Kartik Agaram2019-06-281-0/+0
* | .Kartik Agaram2019-06-081-0/+0
* | Fix stale `initialize-trace-stream`Kartik Agaram2019-06-081-0/+0
* | .Kartik Agaram2019-06-081-0/+0
* | start fleshing out trace support some moreKartik Agaram2019-06-051-0/+0
* | .Kartik Agaram2019-05-271-0/+0
* | new primitive: check-array-equalKartik Agaram2019-05-261-0/+0
* | new primitive: parse-array-of-intsKartik Agaram2019-05-251-0/+0
* | .Kartik Agaram2019-05-251-0/+0
* | new primitive: array-equal?Kartik Agaram2019-05-251-0/+0
* | new primitive for tests: check-string-equalKartik Agaram2019-05-251-0/+0
|/
* 5189Kartik Agaram2019-05-181-0/+0
* 5180Kartik Agaram2019-05-161-0/+0
* complete the skeleton of dquotes.subxKartik Agaram2019-05-151-0/+0
* Merge branch 'dquotes' into dquotes-1Kartik Agaram2019-05-131-0/+0
|\
| * start using the new carry flagKartik Agaram2019-05-131-0/+0
| * 5156 - error-checking on writes to fileKartik Agaram2019-05-111-0/+0
| * 5154Kartik Agaram2019-05-111-0/+0
| * 5153Kartik Agaram2019-05-111-0/+0
* | Merge branch 'master' into dquotes-1Kartik Agaram2019-05-101-0/+0
|\|
| * 5151 - use mmap everywhere we need a heapKartik Agaram2019-05-101-0/+0
| * 5145Kartik Agaram2019-05-041-0/+0
| * 5135Kartik Agaram2019-05-041-0/+0
* | new primitives: append-byte, append-byte-hexKartik Agaram2019-05-021-0/+0
* | standardize function namesKartik Agaram2019-05-021-0/+0
|/
* 5118 - convert int to stringKartik Agaram2019-04-231-0/+0
* 5090Kartik Agaram2019-04-131-0/+0
* 5074Kartik Agaram2019-04-101-0/+0
* 5060Kartik Agaram2019-04-061-0/+0
* 5059Kartik Agaram2019-04-051-0/+0
* 5056Kartik Agaram2019-04-051-0/+0
* 5053Kartik Agaram2019-04-031-0/+0
* 5027Kartik Agaram2019-03-271-0/+0
* 4999Kartik Agaram2019-03-101-0/+0
* 4996 - back on pack.subxKartik Agaram2019-03-081-0/+0
* 4988Kartik Agaram2019-02-251-0/+0
r/commit/ranger/gui/wdisplay.py?h=v1.9.3&id=ae943ecbc21969937b13ac70ab71facc61271a6f'>ae943ecb ^
e657119b ^


ae943ecb ^



d3eff0a9 ^
ae943ecb ^

77f59786 ^
d88232a3 ^
ae943ecb ^

4e01caf1 ^
ae943ecb ^

63502bea ^
d88232a3 ^
ae943ecb ^




d88232a3 ^
9506fb8e ^
49ae0dd1 ^

d621586e ^
d621586e ^


ab1a2682 ^
30b25795 ^
d621586e ^




42fd3690 ^
d88232a3 ^

d621586e ^
31642154 ^
a808a661 ^
d621586e ^
42fd3690 ^



1cb6afa9 ^

a2ccfbe1 ^
1cb6afa9 ^




a808a661 ^
a2ccfbe1 ^
42fd3690 ^



ab1a2682 ^
42fd3690 ^

ab1a2682 ^
42fd3690 ^


a808a661 ^
f257e476 ^
30b25795 ^
7a268c8b ^
dca25f90 ^
7a268c8b ^

9506fb8e ^
31642154 ^
d88232a3 ^
17f83af2 ^
9506fb8e ^
17f83af2 ^
328c6565 ^
9506fb8e ^
30b25795 ^

328c6565 ^
30b25795 ^
ea87d005 ^
30b25795 ^
f257e476 ^
30b25795 ^
328c6565 ^
f257e476 ^
328c6565 ^

419e4aa5 ^
31642154 ^
d88232a3 ^
5805deca ^
f027adc0 ^
77f59786 ^
7d9ae552 ^
871c502d ^
7d9ae552 ^
17f83af2 ^

7d9ae552 ^
b6e32668 ^



7d9ae552 ^
77f59786 ^
ca665e06 ^
dd7a4f63 ^
9506fb8e ^
f027adc0 ^
17f83af2 ^
f027adc0 ^
9506fb8e ^
dd7a4f63 ^
8b60e8ca ^

17f83af2 ^
8b60e8ca ^


31642154 ^
dd7a4f63 ^
5599636d ^
dd7a4f63 ^
f027adc0 ^
5805deca ^

63502bea ^
5805deca ^

dd7a4f63 ^
b810fe28 ^
20f94973 ^

f027adc0 ^



3201b163 ^

2d0c856b ^

3201b163 ^
20f94973 ^

77f59786 ^
548929ab ^
20f94973 ^
ab1a2682 ^
f027adc0 ^
419e4aa5 ^
f027adc0 ^
419e4aa5 ^
5805deca ^


f027adc0 ^

30b25795 ^
dd7a4f63 ^
f027adc0 ^
b19e53f9 ^
77f59786 ^
b19e53f9 ^
17f83af2 ^


b19e53f9 ^
17f83af2 ^
dd7a4f63 ^
b19e53f9 ^

17f83af2 ^
b19e53f9 ^
17f83af2 ^
b19e53f9 ^
17f83af2 ^

b19e53f9 ^
f027adc0 ^
17f83af2 ^
f027adc0 ^
77f59786 ^
20f94973 ^
17f83af2 ^
20f94973 ^
f027adc0 ^
9506fb8e ^
31642154 ^
d88232a3 ^
65cb1a32 ^
dd7a4f63 ^


5599636d ^
dd7a4f63 ^





d494f019 ^


dd7a4f63 ^





db9bb0c9 ^

31642154 ^
db9bb0c9 ^
dd7a4f63 ^









ea87d005 ^
dd7a4f63 ^

31642154 ^
d88232a3 ^
31642154 ^
dd7a4f63 ^
9506fb8e ^
d494f019 ^


22449efd ^
ab7bf8b0 ^
31642154 ^
d494f019 ^

31642154 ^
d494f019 ^

5599636d ^
d494f019 ^
ea87d005 ^
42fd3690 ^

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
                                                                 
 



                                                                      
 






                                                                       
 
                                                                            
         

                     
                    
                        
 









                                                                                        
                                                                           
                                     
                                                                       
                 

                                                       




                                                         
                                   
                           

                                  
                     
                           
                             
 


                      
                                       

                                          
                                  
 
                                         
                                                   
 

                                         
                                                                
 


                                                              



                                                     
                                                                    

                                            
                                                        
                                                                           

                                                            
                                                                              

                                              
                                                                               
                                                                            




                                            
                                                    
 

                           
                              


                                       
                                       
                                                                    




                                            
                                 

                                                           
                       
                                                                   
                                      
 



                                                  

                                                                  
                                                       




                                                                                
                                                       
 



                                               
                                                 

                                                 
                                                      


                                                      
                                                      
 
                                             
                                                                
                                                    

                                                                                   
 
                             
                                                                          
                                   
                                              
                                                                    
                                         
                              

                                                            
                                         
                              
 
                    
                                                       
                       
                                         
                     

                                          
 
                                  
                                                      
                           
 
                                           
 
                                 
 

                                   
                                                  



                                                         
 
                                    
                                                        
 
                                              
                                                       
                                                                    
                                          
                              
 

                                                       
                                                           


                                          
                                        
 
                                                
                                            
                                                    

                            
                                                             

                                          
 
                                                                             

                                                                



                                                             

                                                           

                                                         
 

                                                           
                                                    
                                                                        
 
                                               
                                                              
                             
                                                         
 


                                                                                          

                                                         
                                                                                    
 
                                                
                            
                                                    
                                                  


                                                                                             
                                     
                                                                                 
 

                                                                                 
                                                                    
                                                      
                                                                                         
                               

                                                                                    
                                    
 
                                                                    
 
                                                                        
                                                               
                                                                                           
 
                                          
 
                                    
                                                                                        
                                                    


                                          
                                                





                                                   


                                





                                                                                     

                                                                    
                                                       
 









                                                                             
 

                               
                                    
                                                    
                                                            
                                                            
 


                                                                
                                       
                                       
                                        

                                                    
                                        

                                                         
                                                             
                                                            
 

                                                                               
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""The BrowserColumn widget displays the contents of a directory or file."""
import re
from time import time

from . import Widget
from .pager import Pager

# Don't even try to preview files which mach this regular expression:
PREVIEW_BLACKLIST = re.compile(r"""
		# look at the extension:
		\.(
			# one character extensions:
				[oa]
			# media formats:
				| avi | [mj]pe?g | mp\d | og[gmv] | wm[av] | mkv | flv
				| png | bmp | vob | wav | mpc | flac | divx? | xcf | pdf
			# binary files:
				| torrent | class | so | img | py[co] | dmg
			# containers:
				| iso | rar | zip | 7z | tar | gz | bz2
		)
		# ignore filetype-independent suffixes:
			(\.part|\.bak|~)?
		# ignore fully numerical file extensions:
			(\.\d+)*?
		$
""", re.VERBOSE | re.IGNORECASE)

class BrowserColumn(Pager, Widget):
	main_column = False
	display_infostring = False
	scroll_begin = 0
	target = None
	tagged_marker = '*'
	last_redraw_time = -1

	old_dir = None
	old_cf = None

	def __init__(self, win, level):
		Pager.__init__(self, win)
		Widget.__init__(self, win)
		self.level = level

	def resize(self, y, x, hei, wid):
		Widget.resize(self, y, x, hei, wid)

	def click(self, event):
		"""Handle a MouseEvent"""
		from ranger.fsobject.fsobject import T_DIRECTORY

		if not (event.pressed(1) or event.pressed(3)):
			return False

		if self.target is None:
			pass

		elif self.target.type is T_DIRECTORY:
			index = self.scroll_begin + event.y - self.y

			if event.pressed(1):
				if not self.main_column:
					self.fm.enter_dir(self.target.path)

				if index < len(self.target):
					self.fm.move_pointer(absolute = index)
			elif event.pressed(3):
				try:
					clicked_file = self.target.files[index]
					self.fm.enter_dir(clicked_file.path)
				except:
					pass

		else:
			if self.level > 0:
				self.fm.move_right()

		return True

	def has_preview(self):
		if self.target is None:
			return False

		if self.target.is_file:
			if not self._preview_this_file(self.target):
				return False

		return True

	def poke(self):
		Widget.poke(self)
		self.target = self.env.at_level(self.level)

	def draw(self):
		"""Call either _draw_file() or _draw_directory()"""
		from ranger import log

		if self.target != self.old_dir:
			self.need_redraw = True
			self.old_dir = self.target

		if self.target and self.target.is_directory:
			if self.target.pointed_obj != self.old_cf:
				self.need_redraw = True
				self.old_cf = self.target.pointed_obj

			if self.target.load_content_if_outdated() \
			or self.target.sort_if_outdated() \
			or self.last_redraw_time < self.target.last_update_time:
				self.need_redraw = True

		if self.need_redraw:
			self.win.erase()
			if self.target is None:
				pass
			elif self.target.is_file:
				Pager.open(self)
				self._draw_file()
			elif self.target.is_directory:
				self._draw_directory()
				Widget.draw(self)
			self.need_redraw = False
			self.last_redraw_time = time()

	def _preview_this_file(self, target):
		maxsize = self.settings.max_filesize_for_preview
		return self.settings.preview_files \
				and not PREVIEW_BLACKLIST.search(target.basename) \
				and (maxsize is None or maxsize >= target.size)

	def _draw_file(self):
		"""Draw a preview of the file, if the settings allow it"""
		self.win.move(0, 0)
		if not self.target.accessible:
			self.win.addnstr("not accessible", self.wid)
			Pager.close(self)
			return

		if not self._preview_this_file(self.target):
			Pager.close(self)
			return

		try:
			f = open(self.target.path, 'r')
		except:
			Pager.close(self)
		else:
			self.set_source(f)
			Pager.draw(self)

	def _draw_directory(self):
		"""Draw the contents of a directory"""
		import stat

		base_color = ['in_browser']

		self.target.use()

		self.win.move(0, 0)

		if not self.target.content_loaded:
			self.color(base_color)
			self.win.addnstr("...", self.wid)
			self.color_reset()
			return

		if self.main_column:
			base_color.append('main_column')

		if not self.target.accessible:
			self.color(base_color, 'error')
			self.win.addnstr("not accessible", self.wid)
			self.color_reset()
			return

		if self.target.empty():
			self.color(base_color, 'empty')
			self.win.addnstr("empty", self.wid)
			self.color_reset()
			return

		self._set_scroll_begin()

		selected_i = self.target.pointer
		for line in range(self.hei):
			i = line + self.scroll_begin

			try:
				drawed = self.target.files[i]
			except IndexError:
				break

			this_color = base_color + list(drawed.mimetype_tuple)
			text = drawed.basename
			tagged = drawed.realpath in self.fm.tags

			if i == selected_i:
				this_color.append('selected')

			if drawed.marked:
				this_color.append('marked')
				if self.main_column:
					text = " " + text

			if tagged:
				this_color.append('tagged')
				if self.main_column:
					text = self.tagged_marker + text

			if drawed.is_directory:
				this_color.append('directory')
			else:
				this_color.append('file')

			if drawed.stat is not None and drawed.stat.st_mode & stat.S_IXUSR:
				this_color.append('executable')

			if drawed.islink:
				this_color.append('link')
				this_color.append(drawed.exists and 'good' or 'bad')

			string = drawed.basename
			try:
				if self.main_column:
					if tagged:
						self.win.addnstr(line, 0, text, self.wid - 2)
					elif self.wid > 1:
						self.win.addnstr(line, 1, text, self.wid - 2)
				else:
					self.win.addnstr(line, 0, text, self.wid)

				if self.display_infostring and drawed.infostring:
					info = drawed.infostring
					x = self.wid - 1 - len(info)
					if x > self.x:
						self.win.addstr(line, x, str(info) + ' ')
			except:
				# the drawing of the last string will cause an error
				# because ncurses tries to move out of the bounds
				pass

			self.color_at(line, 0, self.wid, this_color)

			if self.main_column and tagged and self.wid > 2:
				this_color.append('tag_marker')
				self.color_at(line, 0, len(self.tagged_marker), this_color)

			self.color_reset()

	def _get_scroll_begin(self):
		"""Determines scroll_begin (the position of the first displayed file)"""
		offset = self.settings.scroll_offset
		dirsize = len(self.target)
		winsize = self.hei
		halfwinsize = winsize // 2
		index = self.target.pointer or 0
		original = self.target.scroll_begin
		projected = index - original

		upper_limit = winsize - 1 - offset
		lower_limit = offset

		if original < 0:
			return 0

		if dirsize < winsize:
			return 0

		if halfwinsize < offset:
			return min( dirsize - winsize, max( 0, index - halfwinsize ))

		if original > dirsize - winsize:
			self.target.scroll_begin = dirsize - winsize
			return self._get_scroll_begin()

		if projected < upper_limit and projected > lower_limit:
			return original

		if projected > upper_limit:
			return min( dirsize - winsize,
					original + (projected - upper_limit))

		if projected < upper_limit:
			return max( 0,
					original - (lower_limit - projected))

		return original

	def _set_scroll_begin(self):
		"""Updates the scroll_begin value"""
		self.scroll_begin = self._get_scroll_begin()
		self.target.scroll_begin = self.scroll_begin

	# TODO: does not work if options.scroll_offset is high,
	# relative > 1 and you scroll from scroll_begin = 1 to 0
	def scroll(self, relative):
		"""scroll by n lines"""
		self.need_redraw = True
		self._set_scroll_begin()
		old_value = self.target.scroll_begin
		self.target.scroll_begin += relative
		self._set_scroll_begin()

		if self.target.scroll_begin == old_value:
			self.target.move(relative = relative)
			self.target.scroll_begin += relative

	def __str__(self):
		return self.__class__.__name__ + ' at level ' + str(self.level)