man support

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-10-20 00:01:58 +00:00
parent 0743c7f018
commit 7b5b9f0c94
1 changed files with 27 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import os, commands, re, sets, tempfile import os, commands, re, sets, tempfile
from subprocess import Popen, PIPE, STDOUT 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 point import Point
from method import DATATYPES, Method, Argument from method import DATATYPES, Method, Argument
@ -57,6 +57,32 @@ class Exec(Method):
else: else:
self._doit(w, None, vargs['cmd']) 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): class Pipe(Method):
'''Pipe the buffer's contents through the command, and display the output in a new buffer''' '''Pipe the buffer's contents through the command, and display the output in a new buffer'''
args = [Argument('cmd', datatype="str", prompt="Command: ")] args = [Argument('cmd', datatype="str", prompt="Command: ")]