summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-02-13 03:30:36 +0100
committerhut <hut@lavabit.com>2013-02-13 03:31:02 +0100
commit8a516820081a317b85c6c2ced7901a4000130bf5 (patch)
tree281ed49baf6141942333cb8b3dab63ec8009087d
parentce65794595963f9f72a3022735acdc711412b262 (diff)
downloadranger-8a516820081a317b85c6c2ced7901a4000130bf5.tar.gz
api.commands: add updated_line handler
with this feature, commands can overwrite the line after each quick()
call by changing the attribute "self.updated_line".
-rw-r--r--ranger/api/commands.py1
-rw-r--r--ranger/config/commands.py2
-rw-r--r--ranger/gui/widgets/console.py7
3 files changed, 8 insertions, 2 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index ce381e18..4250a5da 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -90,6 +90,7 @@ class Command(FileManagerAware):
 
     def __init__(self, line, quantifier=None):
         self.line = line
+        self.updated_line = line
         self.args = line.split()
         self.quantifier = quantifier
         try:
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 14e3f918..f945ccf2 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -40,6 +40,8 @@
 # self.args: A list of all (space-separated) arguments to the command.
 # self.quantifier: If this command was mapped to the key "X" and
 #      the user pressed 6X, self.quantifier will be 6.
+# self.updated_line: The quick() method can overwrite this attribute and
+#      the console will use it as the new line.
 # self.arg(n): The n-th argument, or an empty string if it doesn't exist.
 # self.rest(n): The n-th argument plus everything that followed.  For example,
 #      If the command was "search foo bar a b c", rest(2) will be "bar a b c"
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 10458a54..3b2781d8 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -418,8 +418,11 @@ class Console(Widget):
             pass
         else:
             cmd = cls(self.line)
-            if cmd and cmd.quick():
-                self.execute(cmd)
+            if cmd:
+                result = cmd.quick()
+                self.line = cmd.updated_line
+                if result:
+                    self.execute(cmd)
 
     def ask(self, text, callback, choices=['y', 'n']):
         """