From 7b5b9f0c9476da0698b84e9f3b23b25531a8eed7 Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 20 Oct 2008 00:01:58 +0000 Subject: [PATCH] man support --HG-- branch : pmacs2 --- method/shell.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/method/shell.py b/method/shell.py index f542fc7..eb2cabc 100644 --- a/method/shell.py +++ b/method/shell.py @@ -1,7 +1,7 @@ import os, commands, re, sets, tempfile from subprocess import Popen, PIPE, STDOUT -import buffer, default, dirutil, regex, util, window +import buffer, default, dirutil, regex, term, util, window from point import Point from method import DATATYPES, Method, Argument @@ -57,6 +57,32 @@ class Exec(Method): else: self._doit(w, None, vargs['cmd']) +class Man(Exec): + '''Execute a command in a shell and put the output in a new buffer''' + args = [Argument('name', prompt="Program: ")] + def _execute(self, w, **vargs): + name = vargs['name'] + cmd = 'man %r' % name + p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) + output = p.stdout.read() + result = p.wait() + status = os.WEXITSTATUS(result) + if not os.WIFEXITED(result): + err = True + errmsg = "man: killed by signal %r" % os.WTERMSIG(result) + elif status != 0: + err = True + errmsg = "man: failed with status %r" % status + else: + err = False + errmsg = "man: ok" + if output: + xterm = term.XTerm() + output = xterm.filter(output) + switch_to = err or self.show_success + w.application.data_buffer('*Manpage*', output, switch_to=switch_to) + w.set_error(errmsg) + class Pipe(Method): '''Pipe the buffer's contents through the command, and display the output in a new buffer''' args = [Argument('cmd', datatype="str", prompt="Command: ")]