summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-15 14:03:32 +0200
committerhut <hut@lavabit.com>2012-08-15 14:03:32 +0200
commite13ee7febcdfbc149940e13018d8bab26ca6922a (patch)
treea3c5c98ee7589f29aa9f574adbfa42d342c6f7c3
parent3168005e169b64633f8142ff2ccbbae15d44da2a (diff)
downloadranger-e13ee7febcdfbc149940e13018d8bab26ca6922a.tar.gz
Revert "core.runner: removed 's', 'p', 'w' flags to behave like rifle"
This reverts commit d6c78470ba0e3a9923d5cc13a5babaca4d52aecf.

It makes ... little sense atm to remove this.
-rw-r--r--ranger/core/runner.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/ranger/core/runner.py b/ranger/core/runner.py
index 5d2ee16c..f652c15f 100644
--- a/ranger/core/runner.py
+++ b/ranger/core/runner.py
@@ -9,12 +9,15 @@ It gives you highlevel control about how processes are run.
 Example:
 run = Runner(logfunc=print)
 run('sleep 2', wait=True)         # waits until the process exists
-run(['ls', '--help'], flags='t')  # runs in a new terminal
+run(['ls', '--help'], flags='p')  # pipes output to pager
 run()                             # prints an error message
 
 List of allowed flags:
+s: silent mode. output will be discarded.
 f: fork the process.
+p: redirect output to the pager
 c: run only the current file (not handled here)
+w: wait for enter-press afterwards
 r: run application with root privilege (requires sudo)
 t: run application in a new terminal window
 (An uppercase key negates the respective lower case flag)
@@ -150,9 +153,24 @@ class Runner(object):
 		# Evaluate the flags to determine keywords
 		# for Popen() and other variables
 
+		if 'p' in context.flags:
+			popen_kws['stdout'] = PIPE
+			popen_kws['stderr'] = PIPE
+			toggle_ui = False
+			pipe_output = True
+			context.wait = False
+		if 's' in context.flags:
+			devnull_writable = open(os.devnull, 'w')
+			devnull_readable = open(os.devnull, 'r')
+			for key in ('stdout', 'stderr'):
+				popen_kws[key] = devnull_writable
+			popen_kws['stdin'] = devnull_readable
 		if 'f' in context.flags:
 			toggle_ui = False
 			context.wait = False
+		if 'w' in context.flags:
+			if not pipe_output and context.wait: # <-- sanity check
+				wait_for_enter = True
 		if 'r' in context.flags:
 			# TODO: make 'r' flag work with pipes
 			if 'sudo' not in get_executables():