about summary refs log tree commit diff stats
path: root/html/066stream.mu.html
Commit message (Expand)AuthorAgeFilesLines
* 4239Kartik Agaram2018-05-081-4/+4
* 4200Kartik K. Agaram2018-01-271-12/+12
* 4199Kartik K. Agaram2018-01-251-24/+23
* 4165Kartik K. Agaram2017-12-271-2/+2
* 4161Kartik K. Agaram2017-12-151-6/+6
* 4134 - 'input' = 'ingredient'Kartik K. Agaram2017-12-031-6/+6
* 4122Kartik K. Agaram2017-11-151-1/+1
* 4003Kartik K. Agaram2017-09-231-1/+1
* 3901Kartik K. Agaram2017-06-091-1/+1
* 3837Kartik K. Agaram2017-04-191-1/+1
* 3830 - crosslink shape-shifting containers in htmlKartik K. Agaram2017-04-181-11/+11
* 3829Kartik K. Agaram2017-04-181-1/+1
* 3820Kartik K. Agaram2017-04-131-67/+73
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-3/+4
* 3761Kartik K. Agaram2017-03-071-9/+10
* 3716Kartik K. Agaram2016-12-261-0/+2
* 3713 - cross-link calls with definitions in htmlKartik K. Agaram2016-12-261-6/+6
* 3710Kartik K. Agaram2016-12-261-74/+74
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-77/+101
* 3569Kartik K. Agaram2016-10-231-30/+30
* 3431Kartik K. Agaram2016-09-301-3/+3
* 3430Kartik K. Agaram2016-09-281-1/+1
* 3395Kartik K. Agaram2016-09-171-24/+24
* 3355Kartik K. Agaram2016-09-151-3/+3
* 3158Kartik K. Agaram2016-07-271-0/+111
* 2430 - make room for more transformsKartik K. Agaram2015-11-131-80/+0
* 2423 - describe shape-shifting in html docsKartik K. Agaram2015-11-101-2/+2
* 2177Kartik K. Agaram2015-09-071-35/+37
* 2175Kartik K. Agaram2015-09-061-35/+34
* 2062Kartik K. Agaram2015-08-231-1/+1
* 1925Kartik K. Agaram2015-08-031-9/+9
* 1885Kartik K. Agaram2015-07-291-20/+20
* 1853Kartik K. Agaram2015-07-251-1/+1
* 1818Kartik K. Agaram2015-07-181-4/+4
* 1778Kartik K. Agaram2015-07-131-5/+5
* 1631 - update html versionsKartik K. Agaram2015-06-231-0/+79
='/akspecs/ranger/commit/ranger/gui/widgets/statusbar.py?id=cfdbb9d634555f7c036861266e308b512f0baeac'>cfdbb9d6 ^
3201b163 ^



cfdbb9d6 ^

cfdbb9d6 ^

b4b0eb24 ^


cfdbb9d6 ^


































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
















                                                                       
                       
 




                        




                                               




                                                              



                                                                    














                                                                                            



















                                                                                            



                                 




                                                                  


                                   


                                              


                                                      
                                            
                     
                                           








                                                                   






                                                                           



























                                                                   




                                             
 
                                                                      

                                   









                                                                       
                             



                                                                                    

                           

                                                                              


                                                                               


































                                                                              
"""The StatusBar displays information about the currently selected file
in the same form as the "ls -l" command on the left side, and
some additional info about the current directory on the right side.
"""

from . import Widget
from ranger import log
from pwd import getpwuid
from grp import getgrgid
from os import getuid
from time import strftime, localtime

class StatusBar(Widget):
	__doc__ = __doc__
	owners = {}
	groups = {}
	timeformat = '%Y-%m-%d %H:%M'
	override = None

	old_cf = None
	old_mtime = None
	old_wid = None
	result = None

	def __init__(self, win, filelist=None):
		Widget.__init__(self, win)
		self.filelist = filelist
	
	def draw(self):
		"""Draw the statusbar"""

		# each item in the returned array looks like:
		# [ list_with_color_tags,       string       ]
		# [ ['permissions', 'allowed'], '-rwxr-xr-x' ]

		if self.override and isinstance(self.override, str):
			self._draw_message()
		else:
			try:
				mtime = self.env.cf.stat.st_mtime
			except:
				mtime = -1
			if not self.result or self.old_cf != self.env.cf or \
					mtime != self.old_mtime or self.old_wid != self.wid:
				self.old_mtime = mtime
				self.old_cf = self.env.cf
				self.old_wid = self.wid

				left = self._get_left_part()
				right = self._get_right_part()

				self.result = self._combine_parts(left, right)
			self._print_result(self.result)
	
	def _draw_message(self):
		highlight = True
		space_left = self.wid
		starting_point = self.x
		for string in self.override.split('//'):
			highlight = not highlight
			if highlight:
				self.color('in_statusbar', 'text', 'highlight')
			else:
				self.color('in_statusbar', 'text')

			try:
				self.win.addnstr(self.y, starting_point, string, space_left)
			except:
				break
			space_left -= len(string)
			starting_point += len(string)
#			if starting_point >= self.wid:
#				break

	def _get_left_part(self):
		part = []

		if self.filelist is not None:
			target = self.filelist.target.pointed_file
		else:
			target = self.env.at_level(0).pointed_file

		if target is None:
			return part

		if target.accessible is False:
			return part

		perms = target.get_permission_string()
		color = ['permissions']
		if getuid() == target.stat.st_uid:
			color.append('good')
		else:
			color.append('bad')
		part.append([color, perms])

		part.append([['space'], " "])
		part.append([['nlink'], str(target.stat.st_nlink)])
		part.append([['space'], " "])
		part.append([['owner'], self._get_owner(target)])
		part.append([['space'], " "])
		part.append([['group'], self._get_group(target)])
		part.append([['space'], " "])
		if target.islink:
			color = ['link']
			color.append(target.exists and 'good' or 'bad')
			part.append([color, '-> ' + target.readlink])
		else:
			part.append([['mtime'], strftime(self.timeformat, \
					localtime(target.stat.st_mtime))])
		return part
	
	def _get_owner(self, target):
		uid = target.stat.st_uid

		try:
			return self.owners[uid]
		except KeyError:
			try:
				self.owners[uid] = getpwuid(uid)[0]
				return self.owners[uid]
			except KeyError:
				return str(uid)

	def _get_group(self, target):
		gid = target.stat.st_gid

		try:
			return self.groups[gid]
		except KeyError:
			try:
				self.groups[gid] = getgrgid(gid)[0]
				return self.groups[gid]
			except KeyError:
				return str(gid)

	def _get_right_part(self):
		part = []
		if self.filelist is None:
			return part

		target = self.filelist.target
#		target = self.env.at_level(0)

		if not target.content_loaded or not target.accessible:
			return part

		pos = target.scroll_begin
		max_pos = len(target) - self.filelist.hei

		if target.marked_items:
			part.append([['scroll', 'marked'], 'Mrk'])
		elif max_pos > 0:
			if pos == 0:
				part.append([['scroll', 'top'], 'Top'])
			elif pos >= max_pos:
				part.append([['scroll', 'bot'], 'Bot'])
			else:
				part.append([['scroll', 'percentage'], \
					'{0:0>.0f}%'.format(100.0 * pos / max_pos)])
		else:
			part.append([['scroll', 'all'], 'All'])
		return part

	def _combine_parts(self, left, right):
		"""Combines left and right, filling the middle with spaces and
		removing elements which don't have enough room to fit in.
		<left> will be turned into the result (which is also returned).
		"""

		leftsize = sum(len(part[1]) for part in left)
		rightsize = sum(len(part[1]) for part in right)
		sumsize = leftsize + rightsize

		# remove elemets from the left until it fits
		if sumsize > self.wid:
			while len(left) > 0:
				leftsize -= len(left.pop(-1)[1])
				if leftsize + rightsize <= self.wid:
					break
			sumsize = leftsize + rightsize

			# remove elemets from the right until it fits
			if sumsize > self.wid:
				while len(right) > 0:
					rightsize -= len(right.pop(0)[1])
					if leftsize + rightsize <= self.wid:
						break
				sumsize = leftsize + rightsize

		if sumsize < self.wid:
			left.append([ ['space'], " " * (self.wid - sumsize) ])
		left.extend(right)
		return left

	def _print_result(self, result):
		import _curses
		self.win.move(self.y, self.x)
		for part in result:
			self.color('in_statusbar', *part[0])
			try:
				self.win.addstr(part[1])
			except _curses.error:
				pass