grepid: omit stack dump on ctrl+c
This commit is contained in:
parent
ef0e252883
commit
d3bb906b81
55
grepid
55
grepid
@ -59,34 +59,37 @@ def main(argv):
|
|||||||
if len(argv) == 3:
|
if len(argv) == 3:
|
||||||
where = argv[2]
|
where = argv[2]
|
||||||
|
|
||||||
process = Popen(['grep', '--exclude-dir=.svn', '--exclude-dir=.git',
|
try:
|
||||||
'--color=never', '-HIRn', '\<%s\>' % ident, where], stdout=PIPE)
|
process = Popen(['grep', '--exclude-dir=.svn', '--exclude-dir=.git',
|
||||||
|
'--color=never', '-HIRn', '\<%s\>' % ident, where], stdout=PIPE)
|
||||||
|
|
||||||
last_file_name = ''
|
last_file_name = ''
|
||||||
lines = []
|
lines = []
|
||||||
for line in iter(process.stdout.readline, ''):
|
for line in iter(process.stdout.readline, ''):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
m = re.match('(.*):(\d+):(.*)$', line)
|
m = re.match('(.*):(\d+):(.*)$', line)
|
||||||
if m is None:
|
if m is None:
|
||||||
last_file_name = ''
|
last_file_name = ''
|
||||||
sys.stdout.write(m)
|
sys.stdout.write(m)
|
||||||
sys.stdout.write('\n')
|
|
||||||
continue
|
|
||||||
file_name, line_no, content = m.group(1, 2, 3)
|
|
||||||
if file_name != last_file_name:
|
|
||||||
if len(lines) > 0:
|
|
||||||
display_lines(lines, ident)
|
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
last_file_name = file_name
|
continue
|
||||||
ansi_color(sys.stdout, 'yellow')
|
file_name, line_no, content = m.group(1, 2, 3)
|
||||||
sys.stdout.write(last_file_name)
|
if file_name != last_file_name:
|
||||||
sys.stdout.write(':')
|
if len(lines) > 0:
|
||||||
ansi_reset(sys.stdout)
|
display_lines(lines, ident)
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
lines = []
|
last_file_name = file_name
|
||||||
lines.append((line_no, content))
|
ansi_color(sys.stdout, 'yellow')
|
||||||
if len(lines) > 0:
|
sys.stdout.write(last_file_name)
|
||||||
display_lines(lines, ident)
|
sys.stdout.write(':')
|
||||||
|
ansi_reset(sys.stdout)
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
lines = []
|
||||||
|
lines.append((line_no, content))
|
||||||
|
if len(lines) > 0:
|
||||||
|
display_lines(lines, ident)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user