summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-02 09:07:24 +0100
committerhut <hut@lavabit.com>2009-12-02 09:07:24 +0100
commit45cb587d3266efe13efaebfa3fbd324783bec61f (patch)
treeb3b28c2549b5a7bdf015e206184678f9785ce21d
parentd494f0195e5eccc97fd9a135046ff028dec14ae7 (diff)
downloadranger-45cb587d3266efe13efaebfa3fbd324783bec61f.tar.gz
history
-rw-r--r--ranger/conf/keys.py5
-rw-r--r--ranger/conf/options.py8
-rw-r--r--ranger/environment.py36
-rw-r--r--ranger/fm.py3
4 files changed, 50 insertions, 2 deletions
diff --git a/ranger/conf/keys.py b/ranger/conf/keys.py
index 5ad4e510..f1349717 100644
--- a/ranger/conf/keys.py
+++ b/ranger/conf/keys.py
@@ -22,8 +22,13 @@ def initialize_commands(cl):
 	def cd(path):
 		return lambda fm: fm.enter_dir(path)
 
+	def history(n):
+		return lambda fm: fm.history_go(n)
+
 	cl.bind(FM.move_left,           'h', curses.KEY_BACKSPACE, 127)
 	cl.bind(FM.move_right,          'l', curses.KEY_ENTER, ctrl('j'))
+	cl.bind(history(-1),            'H')
+	cl.bind(history(1),             'L')
 	cl.bind(move( relative = 1 ),   'j')
 	cl.bind(move_pages( 0.5 ),      'J')
 	cl.bind(move( relative = -1 ),  'k')
diff --git a/ranger/conf/options.py b/ranger/conf/options.py
index 11ed80cc..e8baa60d 100644
--- a/ranger/conf/options.py
+++ b/ranger/conf/options.py
@@ -4,4 +4,10 @@ def get():
 
 def dummy():
 	""" provide a way of getting options until get() is implemented """
-	return { 'show_hidden': False, 'scroll_offset': 2, 'directories_first': True, 'preview_files' : False }
+	return {
+			'show_hidden': False,
+			'scroll_offset': 2,
+			'directories_first': True,
+			'preview_files' : False,
+			'max_history_size': 20
+			}
diff --git a/ranger/environment.py b/ranger/environment.py
index a15abba2..e0ac646a 100644
--- a/ranger/environment.py
+++ b/ranger/environment.py
@@ -14,6 +14,8 @@ class Environment():
 		self.keybuffer = ()
 		self.copy = None
 		self.termsize = (24, 80)
+		self.history = []
+		self.history_position = -1
 
 	def key_append(self, key):
 		self.keybuffer += (key, )
@@ -53,8 +55,37 @@ class Environment():
 
 			path.move_pointer_to_file_path(last_path)
 			last_path = path
+	
+	def history_go(self, relative):
+		if not self.history:
+			return
+
+		if self.history_position == -1:
+			if relative > 0:
+				return
+			elif relative < 0:
+				self.history_position = max( 0, len(self.history) - 1 + relative )
+		else:
+			self.history_position += relative
+			if self.history_position < 0:
+				self.history_position = 0
+
+		if self.history_position >= len(self.history) - 1:
+			self.history_position = -1
 
-	def enter_dir(self, path):
+		self.enter_dir(self.history[self.history_position], history=False)
+
+	def history_add(self, path):
+		if self.opt['max_history_size']:
+			if len(self.history) > self.history_position > (-1):
+				self.history = self.history[0 : self.history_position + 1]
+			if not self.history or (self.history and self.history[-1] != path):
+				self.history_position = -1
+				self.history.append(path)
+			if len(self.history) > self.opt['max_history_size']:
+				self.history.pop(0)
+
+	def enter_dir(self, path, history = True):
 		# get the absolute path
 		path = normpath(join(self.path, expanduser(path)))
 
@@ -87,5 +118,8 @@ class Environment():
 		self.pwd.sort_if_outdated()
 		self.cf = self.pwd.pointed_file
 
+		if history:
+			self.history_add(path)
+
 		return True
 
diff --git a/ranger/fm.py b/ranger/fm.py
index 55fd64f3..d314fea4 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -41,6 +41,9 @@ class FM():
 				self.execute_file(path)
 		except AttributeError:
 			pass
+
+	def history_go(self, relative):
+		self.env.history_go(relative)
 	
 	def handle_mouse(self):
 		self.ui.handle_mouse(self)
'n322' href='#n322'>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