print filename if multiple files parsed (#59)
This commit is contained in:
parent
b39636c907
commit
86263ffcba
20
pogrep.py
20
pogrep.py
|
@ -137,14 +137,12 @@ def find_in_po(
|
|||
|
||||
def display_results(
|
||||
matches: Sequence[Match],
|
||||
pattern: str,
|
||||
line_number: bool,
|
||||
files_with_matches: bool,
|
||||
args: argparse.Namespace,
|
||||
grep_colors: GrepColors,
|
||||
):
|
||||
"""Display matches as a colorfull table."""
|
||||
files = {match.file for match in matches}
|
||||
if files_with_matches: # Just print filenames
|
||||
if args.files_with_matches: # Just print filenames
|
||||
for file in files:
|
||||
if grep_colors:
|
||||
print(grep_colors.start("fn") + file + grep_colors.NO_COLOR)
|
||||
|
@ -156,9 +154,9 @@ def display_results(
|
|||
term_width = get_terminal_size()[0]
|
||||
for match in matches:
|
||||
left = match.msgid
|
||||
if line_number:
|
||||
if args.line_number:
|
||||
pnum = str(match.line) + ":"
|
||||
if len(files) > 1:
|
||||
if args.print_filenames:
|
||||
pfile = match.file + ":"
|
||||
else:
|
||||
pfile = ""
|
||||
|
@ -173,7 +171,10 @@ def display_results(
|
|||
if grep_colors:
|
||||
print(
|
||||
colorize(
|
||||
tabulate(table, tablefmt="fancy_grid"), pattern, grep_colors, prefixes
|
||||
tabulate(table, tablefmt="fancy_grid"),
|
||||
args.pattern,
|
||||
grep_colors,
|
||||
prefixes,
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
@ -353,6 +354,7 @@ def main():
|
|||
else:
|
||||
grep_colors = None
|
||||
files = process_path(args.path, args.recursive)
|
||||
args.print_filenames = len(files) > 1
|
||||
if args.exclude_dir:
|
||||
files = [
|
||||
f
|
||||
|
@ -378,9 +380,7 @@ def main():
|
|||
return
|
||||
display_results(
|
||||
results,
|
||||
args.pattern,
|
||||
args.line_number,
|
||||
args.files_with_matches,
|
||||
args,
|
||||
grep_colors,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user