about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-01-05 03:00:46 +0100
committerhut <hut@lavabit.com>2010-01-05 03:00:46 +0100
commit4b826595915c221f12a4ebe187e990cc7a08f7f2 (patch)
treecfbe8cffd9add84c915df53bc9ec5355e558bab2 /ranger
parent7e3e8d14402833295ab83ff1591ecbe46867518b (diff)
downloadranger-4b826595915c221f12a4ebe187e990cc7a08f7f2.tar.gz
help: implemented help framework, started writing
Diffstat (limited to 'ranger')
-rw-r--r--ranger/actions.py15
-rw-r--r--ranger/defaults/keys.py7
-rw-r--r--ranger/help/__init__.py31
-rw-r--r--ranger/help/index.py14
-rw-r--r--ranger/help/movement.py24
5 files changed, 90 insertions, 1 deletions
diff --git a/ranger/actions.py b/ranger/actions.py
index 8209c9ab..230f944f 100644
--- a/ranger/actions.py
+++ b/ranger/actions.py
@@ -187,6 +187,21 @@ class Actions(EnvironmentAware, SettingsAware):
 		lines = cleandoc(command.__doc__).split('\n')
 		pager.set_source(lines)
 	
+	def display_help(self, topic='index', narg=None):
+		if not hasattr(self.ui, 'open_pager'):
+			return
+
+		from ranger.help import get_help, get_help_by_index
+
+		if narg is not None:
+			help_text = get_help_by_index(narg)
+		else:
+			help_text = get_help(topic)
+
+		pager = self.ui.open_pager()
+		lines = help_text.split('\n')
+		pager.set_source(lines)
+
 	def display_log(self):
 		if not hasattr(self.ui, 'open_pager'):
 			return
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 02438cbc..8a4cbcb8 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -147,10 +147,11 @@ def initialize_commands(command_list):
 	bind(':', ';', fm.open_console(cmode.COMMAND))
 	bind('>', fm.open_console(cmode.COMMAND_QUICK))
 	bind('/', fm.open_console(cmode.SEARCH))
-	bind('?', fm.open_console(cmode.SEARCH))
 	bind('!', fm.open_console(cmode.OPEN))
 	bind('r', fm.open_console(cmode.OPEN_QUICK))
 
+	bind('?', fm.display_help())
+
 	# definitions which require their own function:
 
 	bind('w', lambda arg: arg.fm.ui.open_taskview())
@@ -207,6 +208,8 @@ def initialize_taskview_commands(command_list):
 	bind('K', wdg.task_move(0))
 	bind('J', wdg.task_move(-1))
 
+	bind('?', fm.display_help())
+
 	bind('dd', wdg.task_remove())
 	bind('w', 'q', ESC, ctrl('d'), ctrl('c'),
 			lambda arg: arg.fm.ui.close_taskview())
@@ -224,6 +227,8 @@ def initialize_embedded_pager_commands(command_list):
 	system_functions(command_list)
 	bind, hint = make_abbreviations(command_list)
 
+	bind('?', fm.display_help())
+
 	bind('j', KEY_DOWN, wdg.move(relative=1))
 	bind('k', KEY_UP, wdg.move(relative=-1))
 	bind('gg', KEY_HOME, wdg.move(absolute=0))
diff --git a/ranger/help/__init__.py b/ranger/help/__init__.py
new file mode 100644
index 00000000..c6d762d6
--- /dev/null
+++ b/ranger/help/__init__.py
@@ -0,0 +1,31 @@
+"""Help files are located here."""
+
+from inspect import cleandoc
+
+NO_TOPIC = """The help topic was not found."""
+
+NO_HELP = """No help was found.
+
+Possibly the program was invoked with "python -QQ" which
+discards all documentation."""
+
+HELP_TOPICS = ('index', 'movement')
+
+def get_docstring_of_module(path, module_name):
+	imported = __import__(path, fromlist=[module_name])
+	return getattr(imported, module_name).__doc__
+
+def get_help(topic):
+	try:
+		doc = get_docstring_of_module('ranger.help', topic)
+	except (ImportError, AttributeError):
+		return NO_TOPIC
+	if isinstance(doc, str):
+		return cleandoc(doc)
+	return NO_HELP
+
+def get_help_by_index(i):
+	try:
+		return get_help(HELP_TOPICS[i])
+	except IndexError:
+		return NO_TOPIC
diff --git a/ranger/help/index.py b/ranger/help/index.py
new file mode 100644
index 00000000..854b8310
--- /dev/null
+++ b/ranger/help/index.py
@@ -0,0 +1,14 @@
+"""
+You are viewing the help index of ranger.
+Press <number>? to view a certain topic or press j to scroll down
+for a general overview about this program.
+
+	0?   This index
+	1?   Basic Movement
+	2?   Quickly switching directories
+
+
+General overview:
+
+Blablabla
+"""
diff --git a/ranger/help/movement.py b/ranger/help/movement.py
new file mode 100644
index 00000000..5f245c47
--- /dev/null
+++ b/ranger/help/movement.py
@@ -0,0 +1,24 @@
+"""
+Ranger has the same, or similar movement keys as vim:
+
+	k    move up
+	j    move down
+	h    move left (in browser: move one directory up)
+	l    move right (in browser: enter this directory, or start this file)
+
+	K    move half the screen up
+	J    move half the screen down
+	H    in browser: move back in history
+	L    in browser: move forward in history
+
+	gg   move to the top
+	G    move to the bottom
+
+By prefixing a number, you can give more precise commands, eg:
+
+	2J   move 2 pages down
+	5gg  move to the 5th line
+	3h   move 3 characters to the left, or move 3 directories up
+
+Special keys like Home, Page Up,.. work as expected.
+"""