summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-08 04:00:55 +0200
committerhut <hut@lavabit.com>2011-10-08 04:00:55 +0200
commit780e5dedb2f7c6bd350b8d7fbded6cbdca4803ba (patch)
tree08bcd3d4e78178244665f504874fd976247b00e8
parent1686dda57e433e9a60f718203e1d235e96dd50fc (diff)
downloadranger-780e5dedb2f7c6bd350b8d7fbded6cbdca4803ba.tar.gz
core.actions: added dump_keybindings()
-rw-r--r--ranger/core/actions.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 79292a06..935534ce 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -17,6 +17,7 @@ import codecs
 import os
 import re
 import shutil
+import subprocess
 import string
 from os.path import join, isdir, realpath
 from os import link, symlink, getcwd
@@ -25,7 +26,7 @@ from inspect import cleandoc
 import ranger
 from ranger.ext.direction import Direction
 from ranger.ext.relative_symlink import relative_symlink
-from ranger.ext.keybinding_parser import key_to_string
+from ranger.ext.keybinding_parser import key_to_string, construct_keybinding
 from ranger.ext.shell_escape import shell_quote
 from ranger import fsobject
 from ranger.core.shared import FileManagerAware, EnvironmentAware, \
@@ -766,6 +767,40 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		self.tabs[self.current_tab] = self.env.cwd.path
 
 	# --------------------------
+	# -- Overview of internals
+	# --------------------------
+
+	def dump_keybindings(self, *contexts):
+		self.ui.suspend()
+		p = subprocess.Popen(['less'], stdin=subprocess.PIPE)
+		def write(string):
+			p.stdin.write(string.encode('utf-8'))
+
+		def recurse(before, pointer):
+			for key, value in pointer.items():
+				keys = before + [key]
+				if isinstance(value, dict):
+					recurse(keys, value)
+				else:
+					write("%12s %s\n" % (construct_keybinding(keys), value))
+		if not contexts:
+			contexts = 'browser', 'console', 'pager', 'taskview'
+
+		try:
+			for context in contexts:
+				write("Keybindings in `%s'\n" % context)
+				if context in self.env.keymaps:
+					recurse([], self.env.keymaps[context])
+				else:
+					write("  None\n")
+				write("\n")
+			p.stdin.close()
+		except IOError:
+			pass
+		p.wait()
+		self.ui.initialize()
+
+	# --------------------------
 	# -- File System Operations
 	# --------------------------