summary refs log tree commit diff stats
path: root/test
Commit message (Expand)AuthorAgeFilesLines
* Renamed ranger/ext/signal_dispatcher to ranger/ext/signalshut2010-10-141-1/+1
* Merge branch 'master' into previewhut2010-10-082-5/+5
|\
| * a little restructurationhut2010-10-022-5/+5
| * Revert 5 commits concerning utf (due to very poor performance)hut2010-09-301-2/+5
| * ext.utfwidth: updated algorithmshut2010-09-301-5/+0
| * ext.utfwidth: stuffhut2010-09-301-0/+2
* | Merge branch 'stable' into previewhut2010-10-0521-12/+268
|\|
| * removed test/__init__.py (not needed)hut2010-08-291-0/+0
| * defaults.keys: key pL to create relative symlinkshut2010-08-291-0/+47
| * Removed symlink in test/hut2010-08-2919-8/+108
| * Changed implementation of container.historyhut2010-08-281-8/+8
| * Fixed historyhut2010-08-261-0/+19
| * tc_human_readable: additional testcase (which fails)hut2010-06-251-0/+4
| * ext.human_readable: more efficient implementationhut2010-06-242-0/+86
* | Merge branch 'master' into previewhut2010-06-221-9/+8
|\|
| * all_benchmarks: shortenedhut2010-06-181-9/+8
* | Merge branch 'master' into previewhut2010-06-0919-86/+121
|\|
| * all_benchmarks.py: fix + cleanuphut2010-06-091-40/+35
| * all_tests.py: cleanuphut2010-06-091-14/+14
| * Changed hashbang line to "#!/usr/bin/env python"hut2010-06-092-2/+2
| * simplified all_tests.py, moved to test/hut2010-06-0719-86/+126
* | gui.ansi: some modifications/completionshut2010-06-031-7/+2
* | added gui/ansi.py from David Barnetts branchhut2010-06-031-0/+45
|/
* Merge branch 'utf'hut2010-05-171-0/+42
|\
| * fixed utf stuffhut2010-05-171-3/+3
| * attempt to fix utf issues (wrong calculation of width)hut2010-05-101-0/+42
* | fsobject.fsobject: applied patcheshut2010-05-141-0/+1
|/
* all_benchmarks: improvedhut2010-05-101-2/+0
* fsobject: don't unnecessarily use abspath() in __init__hut2010-05-061-1/+2
* cleanupshut2010-05-052-3/+6
* Added license header to a few fileshut2010-05-041-0/+15
* bm_loader: stuffhut2010-05-031-1/+35
* test: added TODO, skip broken testshut2010-05-034-5/+25
* changed testdir to /usr/includehut2010-04-291-1/+1
* Separated benchmark from testcasehut2010-04-293-125/+134
* Added tc_loaderhut2010-04-262-1/+186
* tc_displayable: improved (but not fixed) test_boundarieshut2010-04-181-6/+8
* tc_displayable: test_boundaries fails if you run it more often!hut2010-04-181-20/+21
* Fixed unittestshut2010-04-183-3/+5
* moved container.keymap.KeyBuffer into seperate modulehut2010-04-161-0/+1
* keymap: moved simulate_press to where it belongs: tc_newkeyshut2010-04-161-5/+14
* keymap: move translate_keys to ranger.ext.keybinding_parserhut2010-04-161-2/+3
* dirarg: added unit test and almost working implementaitonhut2010-04-131-0/+7
* tc_newkeys: fixed all but one testhut2010-04-091-6/+24
* partially fix tc_newkeyshut2010-04-091-26/+28
* tc_direction: fixedhut2010-04-081-1/+1
* tc_newkey: added 2 failing test cases. Fix it!hut2010-04-081-13/+53
* clean uphut2010-04-081-1/+2
* added KeyManagerhut2010-04-072-2/+39
* tc_newkey: added commenthut2010-04-071-0/+1
i/wtitlebar.py?h=v1.8.0&id=aea67778ad2366b4e4171008af7b0dcd5d91f93b'>^
75367118 ^
d88232a3 ^
75367118 ^
9a78b644 ^

871c502d ^
75367118 ^

d3eff0a9 ^
75367118 ^

d3eff0a9 ^
5805deca ^
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













                                                                          




                                                                    
 
                      

                    
                              
 
                       



                            

                      
                       






                                                                                      


                                                                                
 
                            
                                        






                                                        
 
                                      
                                      
 



                                                                     
                                      


                                    
 


                                                                              
 
                                             
                                       
                                            
                             
                                                 
 

                                                         
 

                                                                             
 
                                       
                                            
                                       

                                                             
 

                                        
                                   

                                             
                                                
                                  
# Copyright (c) 2009, 2010 hut <hut@lavabit.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

"""
The titlebar is the widget at the top, giving you broad orientation.

It displays the current path among other things.
"""

from math import floor

from . import Widget
from ranger.gui.bar import Bar

class TitleBar(Widget):
	old_cf = None
	old_keybuffer = None
	old_wid = None
	result = None
	throbber = ' '

	def draw(self):
		if self.env.cf != self.old_cf or\
				str(self.env.keybuffer) != str(self.old_keybuffer) or\
				self.wid != self.old_wid:
			self.old_wid = self.wid
			self.old_cf = self.env.cf
			self._calc_bar()
		self._print_result(self.result)
		if self.wid > 2:
			self.color('in_titlebar', 'throbber')
			self.win.addnstr(self.y, self.wid - 2, self.throbber, 1)

	def _calc_bar(self):
		bar = Bar('in_titlebar')
		self._get_left_part(bar)
		self._get_right_part(bar)
		try:
			bar.shrink_by_cutting(self.wid)
		except ValueError:
			bar.shrink_by_removing(self.wid)
		self.result = bar.combine()

	def _get_left_part(self, bar):
		import socket, os, pwd

		try:
			username = pwd.getpwuid(os.geteuid()).pw_name
		except:
			username = "???"
		if username == 'root':
			clr = 'bad'
		else:
			clr = 'good'

		bar.add(username, 'hostname', clr, fixedsize=True)
		bar.add('@', 'hostname', clr, fixedsize=True)
		bar.add(socket.gethostname(), 'hostname', clr, fixedsize=True)

		for path in self.env.pathway:
			if path.islink:
				clr = 'link'
			else:
				clr = 'directory'

			bar.add(path.basename, clr)
			bar.add('/', clr, fixedsize=True)

		if self.env.cf is not None:
			bar.add(self.env.cf.basename, 'file', fixedsize=True)

	def _get_right_part(self, bar):
		kb = str(self.env.keybuffer)
		self.old_keybuffer = kb
		bar.addright(kb, 'keybuffer', fixedsize=True)
		bar.addright('  ', 'space', fixedsize=True)

	def _print_result(self, result):
		import _curses
		self.win.move(0, 0)
		for part in result:
			self.color(*part.lst)
			self.addstr(part.string)
		self.color_reset()