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