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.
+"""
.s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/env zsh
# Either run the test with the given name, or rerun the most recently run test.
# Intended to be called from within Vim. Check out the vimrc.vim file.
# Unfortunately this only works with Linux at the moment. Some compiler passes
# take too long to run in emulated mode.

if [[ $2 == 'test-'* ]]
then
  TEST_NAME=$2 envsubst '$TEST_NAME' < run_one_test.subx > /tmp/run_one_test.subx
  FILES=$(ls [0-9]*.subx apps/subx-params.subx $1 |sort |uniq)
  echo $FILES > /tmp/last_run_files
elif [[ -e /tmp/last_run_files ]]
then
  FILES=$(cat /tmp/last_run_files)
else
  echo "no test found"
  exit 0  # don't open trace
fi

set -e

./translate_subx_debug init.linux $(echo $FILES) /tmp/run_one_test.subx
echo running
CFLAGS=$CFLAGS ./bootstrap --trace run a.elf