diff options
-rw-r--r-- | ranger/core/actions.py | 6 | ||||
-rw-r--r-- | ranger/core/loader.py | 43 | ||||
-rwxr-xr-x | ranger/data/scope.sh | 2 |
3 files changed, 34 insertions, 17 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index c0d3e025..5adf42c9 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -594,11 +594,13 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): if found == False: data['loading'] = True loadable = CommandLoader(args=[self.settings.preview_script, - path, str(width), str(height)], + path, str(width), str(height)], read=True, silent=True, descr="Getting preview of %s" % path) def on_after(signal): + self.notify("%s complete" % path) exit = signal.process.poll() - content = signal.process.stdout.read() + content = signal.loader.stdout_buffer + content += signal.process.stdout.read() if exit == 0: data[(width, height)] = content elif exit == 3: diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 5e652a28..28171042 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -56,49 +56,64 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware): """ finished = False process = None - def __init__(self, args, descr, silent=False): + def __init__(self, args, descr, silent=False, read=False): SignalDispatcher.__init__(self) Loadable.__init__(self, self.generate(), descr) self.args = args self.silent = silent + self.read = read + self.stdout_buffer = "" def generate(self): self.process = process = Popen(self.args, stdout=PIPE, stderr=PIPE) - self.signal_emit('before', process=process) - if self.silent: + self.signal_emit('before', process=process, loader=self) + if self.silent and not self.read: while process.poll() is None: yield sleep(0.03) else: + selectlist = [] + if self.read: + selectlist.append(process.stdout) + if not self.silent: + selectlist.append(process.stderr) while process.poll() is None: yield try: - rd, _, __ = select.select( - [process.stderr], [], [], 0.03) + rd, _, __ = select.select(selectlist, [], [], 0.03) if rd: - error = process.stderr.readline().decode('utf-8') - if error: - self.fm.notify(error, bad=True) + rd = rd[0] + read = rd.read(512) + if rd == process.stderr and read: + self.fm.notify(read, bad=True) + elif rd == process.stdout and read: + self.stdout_buffer += read except select.error: sleep(0.03) self.finished = True - self.signal_emit('after', process=process) + self.signal_emit('after', process=process, loader=self) def pause(self): if not self.finished and not self.paused: - self.process.send_signal(20) + try: + self.process.send_signal(20) + except: + pass Loadable.pause(self) - self.signal_emit('pause', process=self.process) + self.signal_emit('pause', process=self.process, loader=self) def unpause(self): if not self.finished and self.paused: - self.process.send_signal(18) + try: + self.process.send_signal(18) + except: + pass Loadable.unpause(self) - self.signal_emit('unpause', process=self.process) + self.signal_emit('unpause', process=self.process, loader=self) def destroy(self): - self.signal_emit('destroy', process=self.process) + self.signal_emit('destroy', process=self.process, loader=self) if self.process: self.process.kill() diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index f4e91d64..788ec33c 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -41,7 +41,7 @@ case "$extension" in exit 1;; # HTML Pages: htm|html|xhtml) - have lynx && lynx -dump "$path" | head -n $maxln && exit 5 + have lynx && lynx -dump "$path" | head -n $maxln && exit 5 have elinks && elinks -dump "$path" | head -n $maxln && exit 5 ;; # fall back to highlight/cat if theres no lynx/elinks esac |