about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/keys.py39
-rw-r--r--ranger/container/commandlist.py19
-rw-r--r--ranger/container/environment.py1
-rw-r--r--ranger/defaults/keys.py31
-rw-r--r--ranger/gui/ui.py6
-rw-r--r--ranger/gui/widgets/browserview.py7
6 files changed, 56 insertions, 47 deletions
diff --git a/ranger/api/keys.py b/ranger/api/keys.py
index 308fab2b..be01871d 100644
--- a/ranger/api/keys.py
+++ b/ranger/api/keys.py
@@ -22,28 +22,32 @@ from ranger.gui.widgets import console_mode as cmode
 from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
 
 def make_abbreviations(command_list):
-	def bind(*args):
-		lastarg = args[-1]
-		if hasattr(lastarg, '__call__'):
-			# do the binding
-			command_list.bind(lastarg, *args[:-1])
+	def bind(*args, **keywords):
+		if keywords:
+			command_list.show(*args, **keywords)
 		else:
-			# act as a decorator. eg:
-			#    @bind('a')
-			#    def do_stuff(arg):
-			#       arg.fm.ui.do_stuff()
-			#
-			# is equivalent to:
-			#    bind('a', lambda arg: arg.fm.ui.do_stuff())
-			return lambda fnc: command_list.bind(fnc, *args)
-
-	def hint(*args):
-		command_list.hint(args[-1], *args[:-1])
+			lastarg = args[-1]
+			if hasattr(lastarg, '__call__'):
+				# do the binding
+				command_list.bind(lastarg, *args[:-1])
+			else:
+				# act as a decorator. eg:
+				#    @bind('a')
+				#    def do_stuff(arg):
+				#       arg.fm.ui.do_stuff()
+				#
+				# is equivalent to:
+				#    bind('a', lambda arg: arg.fm.ui.do_stuff())
+				return lambda fnc: command_list.bind(fnc, *args)
+
+	def show(*args, **keywords):
+		command_list.show(*args, **keywords)
 
 	def alias(*args):
 		command_list.alias(*args)
 
-	return bind, hint, alias
+	return bind, alias
+
 
 class Wrapper(object):
 	def __init__(self, firstattr):
@@ -129,4 +133,3 @@ def replace_narg(number, function, args, keywords):
 			keywords = dict(keywords)
 			keywords[NARG_KEYWORD] = number
 	return args, keywords
-
diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py
index c236eb55..01e28d73 100644
--- a/ranger/container/commandlist.py
+++ b/ranger/container/commandlist.py
@@ -12,6 +12,8 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+from ranger.ext.openstruct import OpenStruct
+
 class CommandArgument(object):
 	def __init__(self, fm, displayable, keybuffer):
 		self.fm = fm
@@ -115,13 +117,13 @@ class CommandList(object):
 		for key in cmd.keys:
 			self.paths[key] = cmd
 
-	def hint(self, text, *keys):
-		"""create a Hint object and assign it to the given key combinations."""
+	def show(self, *keys, **keywords):
+		"""create a Show object and assign it to the given key combinations."""
 		if len(keys) == 0: return
 
 		keys = tuple(map(self._str_to_tuple, keys))
 
-		obj = Hint(text, keys)
+		obj = Show(keywords, keys)
 
 		self.commandlist.append(obj)
 		for key in obj.keys:
@@ -184,18 +186,17 @@ class AliasedCommand(Command):
 
 	execute = property(get_execute)
 
-class Hint(object):
-	"""Hints display text without clearing the keybuffer"""
+
+class Show(object):
+	"""Show objects do things without clearing the keybuffer"""
 
 	keys = []
 	text = ''
 
-	def __init__(self, text, keys):
+	def __init__(self, dictionary, keys):
 		self.keys = set(keys)
-		self.text = text
+		self.show_obj = OpenStruct(dictionary)
 
-#	def __str__(self):
-#		return 'Hint({0})'.format(str(self.keys))
 
 def _make_getter(paths, key):
 	def getter():
diff --git a/ranger/container/environment.py b/ranger/container/environment.py
index d8e5e7f8..b720daf3 100644
--- a/ranger/container/environment.py
+++ b/ranger/container/environment.py
@@ -27,6 +27,7 @@ class Environment(SettingsAware):
 	pwd = None  # current directory
 	cf = None  # current file
 	copy = None
+	cmd = None
 	cut = None
 	termsize = None
 	history = None
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 7f508d03..e0604450 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -35,7 +35,7 @@ Check ranger.keyapi for more information
 from ranger.api.keys import *
 
 def _vimlike_aliases(command_list):
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 
 	# the key 'k' will always do the same as KEY_UP, etc.
 	alias(KEY_UP, 'k')
@@ -51,7 +51,7 @@ def _vimlike_aliases(command_list):
 def initialize_commands(command_list):
 	"""Initialize the commands for the main user interface"""
 
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 
 	# -------------------------------------------------------- movement
 	_vimlike_aliases(command_list)
@@ -90,7 +90,7 @@ def initialize_commands(command_list):
 	bind('dd', fm.cut())
 	bind('pp', fm.paste())
 	bind('pl', fm.paste_symlink())
-	hint('p', 'press //p// once again to confirm pasting' \
+	bind('p', hint='press //p// once again to confirm pasting' \
 			', or //l// to create symlinks')
 
 	# ---------------------------------------------------- run programs
@@ -100,16 +100,16 @@ def initialize_commands(command_list):
 	bind('du', fm.execute_command('du --max-depth=1 -h | less'))
 
 	# -------------------------------------------------- toggle options
-	hint('b', "show_//h//idden //p//review_files //d//irectories_first " \
+	bind('b', hint="bind_//h//idden //p//review_files //d//irectories_first " \
 			"//c//ollapse_preview flush//i//nput")
-	bind('bh', fm.toggle_boolean_option('show_hidden'))
+	bind('bh', fm.toggle_boolean_option('bind_hidden'))
 	bind('bp', fm.toggle_boolean_option('preview_files'))
 	bind('bi', fm.toggle_boolean_option('flushinput'))
 	bind('bd', fm.toggle_boolean_option('directories_first'))
 	bind('bc', fm.toggle_boolean_option('collapse_preview'))
 
 	# ------------------------------------------------------------ sort
-	hint('o', 'O', "//s//ize //b//ase//n//ame //m//time //t//ype //r//everse")
+	bind('o', 'O', hint="//s//ize //b//ase//n//ame //m//time //t//ype //r//everse")
 	sort_dict = {
 		's': 'size',
 		'b': 'basename',
@@ -137,7 +137,7 @@ def initialize_commands(command_list):
 	bind('cd', fm.open_console(cmode.COMMAND, 'cd '))
 	bind('f', fm.open_console(cmode.COMMAND_QUICK, 'find '))
 	bind('tf', fm.open_console(cmode.COMMAND, 'filter '))
-	hint('d', 'd//u// (disk usage) d//d// (cut)')
+	bind('d', hint='d//u// (disk usage) d//d// (cut)')
 
 	# --------------------------------------------- jump to directories
 	bind('gh', fm.cd('~'))
@@ -164,13 +164,14 @@ def initialize_commands(command_list):
 	bind('cc', fm.search(order='ctime'))
 	bind('cm', fm.search(order='mimetype'))
 	bind('cs', fm.search(order='size'))
-	hint('c', '//c//time //m//imetype //s//ize')
+	bind('c', hint='//c//time //m//imetype //s//ize')
 
 	# ------------------------------------------------------- bookmarks
 	for key in ALLOWED_BOOKMARK_KEYS:
 		bind("`" + key, "'" + key, fm.enter_bookmark(key))
 		bind("m" + key, fm.set_bookmark(key))
 		bind("um" + key, fm.unset_bookmark(key))
+	bind("`", "'", "m", draw_bookmarks=True)
 
 	# ---------------------------------------------------- change views
 	bind('i', fm.display_file())
@@ -195,7 +196,7 @@ def initialize_commands(command_list):
 
 def initialize_console_commands(command_list):
 	"""Initialize the commands for the console widget only"""
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 
 	# -------------------------------------------------------- movement
 	bind(KEY_UP, wdg.history_move(-1))
@@ -235,7 +236,7 @@ def initialize_console_commands(command_list):
 
 def initialize_taskview_commands(command_list):
 	"""Initialize the commands for the TaskView widget"""
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 	_basic_movement(command_list)
 	_vimlike_aliases(command_list)
 	_system_functions(command_list)
@@ -254,21 +255,21 @@ def initialize_taskview_commands(command_list):
 
 
 def initialize_pager_commands(command_list):
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 	_base_pager_commands(command_list)
 	bind('q', 'i', ESC, KEY_F1, lambda arg: arg.fm.ui.close_pager())
 	command_list.rebuild_paths()
 
 
 def initialize_embedded_pager_commands(command_list):
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 	_base_pager_commands(command_list)
 	bind('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager())
 	command_list.rebuild_paths()
 
 
 def _base_pager_commands(command_list):
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 	_basic_movement(command_list)
 	_vimlike_aliases(command_list)
 	_system_functions(command_list)
@@ -288,7 +289,7 @@ def _base_pager_commands(command_list):
 
 def _system_functions(command_list):
 	# Each commandlist should have this bindings
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 
 	bind(KEY_RESIZE, fm.resize())
 	bind(KEY_MOUSE, fm.handle_mouse())
@@ -297,7 +298,7 @@ def _system_functions(command_list):
 
 
 def _basic_movement(command_list):
-	bind, hint, alias = make_abbreviations(command_list)
+	bind, alias = make_abbreviations(command_list)
 
 	bind(KEY_DOWN, wdg.move(relative=1))
 	bind(KEY_UP, wdg.move(relative=-1))
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index f362a011..a8353c7d 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -134,9 +134,11 @@ class UI(DisplayableContainer):
 			self.env.key_clear()
 			return
 
-		if hasattr(cmd, 'text'):
+		self.env.cmd = cmd
+
+		if hasattr(cmd, 'show_obj') and hasattr(cmd.show_obj, 'hint'):
 			if hasattr(self, 'hint'):
-				self.hint(cmd.text)
+				self.hint(cmd.show_obj.hint)
 		elif hasattr(cmd, 'execute'):
 			try:
 				cmd.execute_wrap(self)
diff --git a/ranger/gui/widgets/browserview.py b/ranger/gui/widgets/browserview.py
index 66b0f6bf..5287ebb6 100644
--- a/ranger/gui/widgets/browserview.py
+++ b/ranger/gui/widgets/browserview.py
@@ -59,9 +59,10 @@ class BrowserView(Widget, DisplayableContainer):
 		self.add_child(self.pager)
 
 	def draw(self):
-		if str(self.env.keybuffer) in ("`", "'", "m"):
-			self._draw_bookmarks()
-		else:
+		try:
+			if self.env.cmd.show_obj.draw_bookmarks:
+				self._draw_bookmarks()
+		except AttributeError:
 			if self.need_clear:
 				self.win.erase()
 				self.need_redraw = True