branch : pmacs2
This commit is contained in:
moculus 2009-03-21 19:41:33 +00:00
parent aed3461c37
commit 4e812a0f3c
2 changed files with 28 additions and 27 deletions

View File

@ -15,6 +15,10 @@ def resolve_path(w, y=None):
name = resolve_name(w) name = resolve_name(w)
path = os.path.join(w.buffer.path, name) path = os.path.join(w.buffer.path, name)
return path return path
def resolve_name_path(w, y=None):
name = resolve_name(w)
path = os.path.join(w.buffer.path, name)
return name, path
def find_name(w, s): def find_name(w, s):
found = False found = False

View File

@ -1,21 +1,22 @@
import os, commands, re, tempfile import os
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, regex, term, util, window import dirutil
from point import Point import regex
from buffer.emul import XTermBuffer
from method import Method, Argument from method import Method, arg
from term import XTerm
from window import Window
class Exec(Method): class Exec(Method):
'''Execute a command in a shell and put the output in a new buffer''' '''Execute a command in a shell and put the output in a new buffer'''
show_success = True show_success = True
args = [Argument('cmd', prompt="Exec: ", datatype='shell')] args = [arg('cmd', dt='shell', p="Exec: ")]
def _doit(self, w, path, cmd, cmdname=None, bufname=None, cmddir=None, opts={}): def _doit(self, w, path, cmd, cmdname=None, bufname=None, cmddir=None, opts={}):
if cmddir: if cmddir: cmd = "cd %r && %s" % (cmddir, cmd)
cmd = "cd %r && %s" % (cmddir, cmd)
d = dict(opts) d = dict(opts)
if path: if path: d['path'] = path
d['path'] = path
try: try:
cmd = cmd % d cmd = cmd % d
except: except:
@ -46,8 +47,7 @@ class Exec(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
if w.buffer.btype == 'dir': if w.buffer.btype == 'dir':
name = dirutil.resolve_name(w) name, path = dirutil.resolve_name_path(w)
path = dirutil.resolve_path(w)
self._doit(w, path, vargs['cmd']) self._doit(w, path, vargs['cmd'])
dirutil.find_name(w, name) dirutil.find_name(w, name)
elif hasattr(w.buffer, 'path'): elif hasattr(w.buffer, 'path'):
@ -58,7 +58,7 @@ class Exec(Method):
class Man(Exec): class Man(Exec):
'''Execute a command in a shell and put the output in a new buffer''' '''Execute a command in a shell and put the output in a new buffer'''
args = [Argument('name', prompt="Program: ")] args = [arg('name', p="Program: ")]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
name = vargs['name'] name = vargs['name']
cmd = 'man %r' % name cmd = 'man %r' % name
@ -76,15 +76,15 @@ class Man(Exec):
err = False err = False
errmsg = "man: ok" errmsg = "man: ok"
if output: if output:
xterm = term.XTerm(cbuf=True) xterm = XTerm(cbuf=True)
output = xterm.term_filter(output) s = xterm.term_filter(output)
switch_to = err or self.show_success switch = err or self.show_success
w.application.color_data_buffer('*Manpage*', output, switch_to=switch_to) w.application.color_data_buffer('*Manpage*', s, switch_to=switch)
w.set_error(errmsg) 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="shell", prompt="Pipe: ")] args = [arg('cmd', dt="shell", p="Pipe: ")]
def _parse(self, w, **vargs): def _parse(self, w, **vargs):
# return 3 things: prog name, cmd, and whether to use the shell # return 3 things: prog name, cmd, and whether to use the shell
m = regex.shell_command.match(vargs['cmd']) m = regex.shell_command.match(vargs['cmd'])
@ -126,30 +126,27 @@ class Pipe(Method):
class Grep(Pipe): class Grep(Pipe):
'''Grep the buffer's contents for instances of a pattern, and display them in a new buffer''' '''Grep the buffer's contents for instances of a pattern, and display them in a new buffer'''
args = [Argument('pattern', datatype="str", prompt="Pattern: ")] args = [arg('pattern', dt="str", p="Pattern: ")]
def _parse(self, w, **vargs): def _parse(self, w, **vargs):
return ('grep', ('grep', '-E', '-n', vargs['pattern']), False) return ('grep', ('grep', '-E', '-n', vargs['pattern']), False)
class Sed(Pipe): class Sed(Pipe):
'''Push the buffer's contents through a sed expression''' '''Push the buffer's contents through a sed expression'''
args = [Argument('expression', datatype="str", prompt="Expression: ")] args = [arg('expression', dt="str", p="Expression: ")]
def _parse(self, w, **vargs): def _parse(self, w, **vargs):
return ('grep', ('sed', '-r', '-e', vargs['expression']), False) return ('grep', ('sed', '-r', '-e', vargs['expression']), False)
class Interact(Method): class Interact(Method):
'''Interact with a program via a PTY''' '''Interact with a program via a PTY'''
args = [Argument('bname', datatype="str", prompt="Buffer Name: ", args = [arg('bname', dt="str", p="Buffer Name: ", dv=lambda w: '*Interact*'),
default=default.build_constant('*Interact*')), arg('cmd', dt="shell", p="Command: ", dv=lambda w: 'bash')]
Argument('cmd', datatype="shell", prompt="Command: ",
default=default.build_constant('bash'))]
modename = None modename = None
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
bname = vargs['bname'] bname = vargs['bname']
cmd = vargs['cmd'] cmd = vargs['cmd']
a = w.application a = w.application
a.close_buffer_by_name(bname) a.close_buffer_by_name(bname)
b = buffer.emul.XTermBuffer(a, 'bash', ['-c', cmd], name=bname, b = XTermBuffer(a, 'bash', ['-c', cmd], name=bname, modename=self.modename)
modename=self.modename)
a.add_buffer(b) a.add_buffer(b)
window.Window(b, a) Window(b, a)
if a.window().buffer is not b: if a.window().buffer is not b:
a.switch_buffer(b) a.switch_buffer(b)