Skip to content

Commit

Permalink
grep mode: fix multiline case
Browse files Browse the repository at this point in the history
  • Loading branch information
regit committed Mar 22, 2018
1 parent bfaef58 commit 2e7322d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/coccigrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, mfile, mline, mcol, mlineend, mcolend, search):
self.columnend = int(mcolend)
self.search = search
self.start_at = self.line
self.stop_at = self.line
self.stop_at = int(mlineend)
self.trailer = ""

def display(self, stype, mode='raw', oformat='term'):
Expand Down Expand Up @@ -163,19 +163,18 @@ def display(self, stype, mode='raw', oformat='term'):
elif mode == 'emacs':
output += "%s:%s: (%s %s%s): %s" % (self.file, i + 1,
stype, ptype, pmatch, lines[i])
elif mode == 'grep' and stdout.isatty():
lineend = lines[i][self.columnend:]
if self.search.attribute:
lineend = lineend.replace(self.search.attribute,"\033[0;31m" + self.search.attribute + "\033[0m", 1)
content = lines[i][:self.column] + \
"\033[0;32m" + lines[i][self.column:self.columnend] + "\033[0m" \
+ lineend
output += "%s:%s:\t%s" % (self.file, i + 1, content)
elif i == self.line - 1:
if mode == 'grep' and stdout.isatty():
lineend = lines[i][self.columnend:]
if self.search.attribute:
lineend = lineend.replace(self.search.attribute,"\033[0;31m" + self.search.attribute + "\033[0m", 1)
content = lines[i][:self.column] + \
"\033[0;32m" + lines[i][self.column:self.columnend] + "\033[0m" \
+ lineend
output += "%s:%s:\t%s" % (self.file, i + 1, content)
else:
content = lines[i]
output += "%s:%s (%s %s%s):\t%s" % (self.file, i + 1,
stype, ptype, pmatch, content)
content = lines[i]
output += "%s:%s (%s %s%s):\t%s" % (self.file, i + 1,
stype, ptype, pmatch, content)
else:
output += "%s-%s %s - %s" % (self.file, i + 1,
' ' * (2 + len(stype + ptype + pmatch)), lines[i])
Expand Down

0 comments on commit 2e7322d

Please sign in to comment.