summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--TODO4
-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
6 files changed, 93 insertions, 2 deletions
diff --git a/TODO b/TODO
index 9115fc90..b3475548 100644
--- a/TODO
+++ b/TODO
@@ -20,7 +20,8 @@ General
    (X) #14  09/12/29  make filelists inherit from pagers
    (X) #15  09/12/29  better way of running processes!!~
    (X) #16  10/01/01  list of bookmarks
-   ( ) #21  10/01/01  write help!
+   (X) #21  10/01/01  write help!
+   ( ) #22  10/01/03  add getopt options to change flags/mode
 
 
 Bugs
@@ -28,6 +29,7 @@ Bugs
    (X) #17  10/01/01  why do bookmarks disappear sometimes?
    (X) #18  10/01/01  fix notify widget (by adding a LogView?)
    (X) #19  10/01/01  resizing after pressing g
+   ( ) #23  10/01/04  stop dir loading with ^C -> wont load anymore
 
 
 Ideas
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.
+"""