new pipe command, and grep command improvements
--HG-- branch : pmacs2
This commit is contained in:
parent
1e3a417fb9
commit
3a36d4f149
|
@ -546,7 +546,8 @@ class Application(object):
|
|||
|
||||
if w.margins_visible:
|
||||
for (limit, shade) in w.margins:
|
||||
if limit <= self.x:
|
||||
#if limit <= self.x:
|
||||
if limit < self.x:
|
||||
for j in range(0, slot.height):
|
||||
char = self.win.inch(j + slot.offset, limit) & 255
|
||||
attr = color.build('default', shade, 'bold')
|
||||
|
|
38
method.py
38
method.py
|
@ -1405,12 +1405,23 @@ class RegisterRestore(Method):
|
|||
name = name[0:self.MAX_REG] + '...'
|
||||
w.set_error('Restored %r from register %r' % (text2, name2))
|
||||
|
||||
class Grep(Method):
|
||||
class Pipe(Method):
|
||||
'''help here'''
|
||||
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
|
||||
args = [Argument('cmd', datatype="str", prompt="Command: ")]
|
||||
def _parse(self, w, **vargs):
|
||||
m = regex.shell_command.match(vargs['cmd'])
|
||||
if m:
|
||||
prog = m.group(0)
|
||||
return (prog, vargs['cmd'])
|
||||
else:
|
||||
return (None, None)
|
||||
|
||||
def _execute(self, w, **vargs):
|
||||
cmd = ("/usr/bin/grep", '-E', '-n', vargs['pattern'], '-')
|
||||
pipe = popen2.Popen3(cmd, capturestderr=True)
|
||||
(prog, cmd) = self._parse(w, **vargs)
|
||||
if prog is None:
|
||||
return
|
||||
|
||||
pipe = popen2.Popen4(cmd)
|
||||
pid = pipe.pid
|
||||
|
||||
indata = w.buffer.make_string()
|
||||
|
@ -1418,16 +1429,15 @@ class Grep(Method):
|
|||
pipe.tochild.close()
|
||||
|
||||
outdata = pipe.fromchild.read()
|
||||
errdata = pipe.childerr.read()
|
||||
status = pipe.wait() >> 8
|
||||
|
||||
if status == 0:
|
||||
num = len(outdata.split('\n'))
|
||||
w.application.data_buffer("*Grep*", outdata, switch_to=True)
|
||||
w.application.set_error("Grep: %d matches found" % num)
|
||||
elif status == 1:
|
||||
w.application.set_error("Grep: no matches found")
|
||||
else:
|
||||
w.application.data_buffer("*Grep*", outdata, switch_to=True)
|
||||
w.set_error("Grep: error (exited with status %d)" % status)
|
||||
bufname = '*%s*' % self.name.title()
|
||||
w.application.data_buffer(bufname, outdata, switch_to=True)
|
||||
w.set_error("%s exited with status %d" % (prog, status))
|
||||
|
||||
class Grep(Pipe):
|
||||
'''help here'''
|
||||
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
|
||||
def _parse(self, w, **vargs):
|
||||
return ('grep', ('/usr/bin/grep', '-E', '-n', vargs['pattern']))
|
||||
|
Loading…
Reference in New Issue