summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-12-03 23:00:23 +0100
committerhut <hut@lavabit.com>2012-12-04 23:32:21 +0100
commitca1a5d21e6564c022b810c4f52daf61fc4f3ea30 (patch)
tree06a7779a2ed348eb93b71ca84f0b36bad1fcbabd /ranger
parent7836af4f970a8f2b7782dc21e16540da57279c69 (diff)
downloadranger-ca1a5d21e6564c022b810c4f52daf61fc4f3ea30.tar.gz
updated man page, improved hooks
Diffstat (limited to 'ranger')
-rw-r--r--ranger/api/__init__.py28
-rw-r--r--ranger/core/fm.py9
-rw-r--r--ranger/core/main.py3
3 files changed, 31 insertions, 9 deletions
diff --git a/ranger/api/__init__.py b/ranger/api/__init__.py
index cc64a7c0..1121197a 100644
--- a/ranger/api/__init__.py
+++ b/ranger/api/__init__.py
@@ -1,4 +1,28 @@
 """
-Files in this module contain helper functions used in
-configuration files.
+Files in this module contain helper functions used in configuration files.
 """
+
+# Hooks for use in plugins:
+
+def hook_init(fm):
+	"""
+	Parameters:
+	  fm = the file manager instance
+	Return Value:
+	  ignored
+
+	This hook is executed after fm is initialized but before fm.ui is
+	initialized.  You can safely print to stdout and have access to fm to add
+	keybindings and such.
+	"""
+
+def hook_ready(fm):
+	"""
+	Parameters:
+	  fm = the file manager instance
+	Return Value:
+	  ignored
+
+	This hook is executed after the user interface is initialized.  You should
+	NOT print anything to stdout anymore from here on.  Use fm.notify instead.
+	"""
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index b32e5730..3c100532 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -14,7 +14,7 @@ import socket
 import stat
 import sys
 
-import ranger
+import ranger.api
 from ranger.core.actions import Actions
 from ranger.core.tab import Tab
 from ranger.container.tags import Tags
@@ -28,9 +28,6 @@ from ranger.ext.signals import SignalDispatcher
 from ranger import __version__
 from ranger.core.loader import Loader
 
-def init_hook():
-	pass
-
 class FM(Actions, SignalDispatcher):
 	input_blocked = False
 	input_blocked_until = 0
@@ -126,8 +123,6 @@ class FM(Actions, SignalDispatcher):
 			self.notify(text, bad=True)
 		self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)
 
-		init_hook()
-
 	def destroy(self):
 		debug = ranger.arg.debug
 		if self.ui:
@@ -250,6 +245,8 @@ class FM(Actions, SignalDispatcher):
 		has_throbber = hasattr(ui, 'throbber')
 		zombies = self.run.zombies
 
+		ranger.api.hook_ready(self)
+
 		try:
 			while True:
 				loader.work()
diff --git a/ranger/core/main.py b/ranger/core/main.py
index df2a922e..dd07bff8 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -13,7 +13,7 @@ load_default_config = True
 def main():
 	"""initialize objects and run the filemanager"""
 	import locale
-	import ranger
+	import ranger.api
 	from ranger.core.shared import FileManagerAware, SettingsAware
 	from ranger.core.fm import FM
 
@@ -115,6 +115,7 @@ def main():
 
 		# Run the file manager
 		fm.initialize()
+		ranger.api.hook_init(fm)
 		fm.ui.initialize()
 
 		if arg.cmd: