Skip to content

Commit

Permalink
Merge pull request #72 from bee-san/rec-fix
Browse files Browse the repository at this point in the history
 Filename name in the column is now actually there
 Filename column is only printed if input is a folder
  • Loading branch information
bee-san authored Jun 10, 2021
2 parents bf8f30d + a42cf56 commit 70def10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pywhat/printer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import os

from rich.console import Console
from rich.table import Table


class Printing:
def pretty_print(self, text: dict):
def pretty_print(self, text: dict, text_input):
console = Console(highlight=False)

to_out = ""
Expand All @@ -27,8 +28,8 @@ def pretty_print(self, text: dict):
table.add_column("Identified as", overflow="fold")
table.add_column("Description", overflow="fold")

if list(text["Regexes"].keys())[0] == text:
# if input was text, do not add a filename column
if os.path.isdir(text_input):
# if input is a folder, add a filename column
table.add_column("Filename", overflow="fold")

for key, value in text["Regexes"].items():
Expand Down Expand Up @@ -56,18 +57,18 @@ def pretty_print(self, text: dict):
if not description:
description = "None"

if key == "text":
if os.path.isdir(text_input):
table.add_row(
matched,
name,
description,
filename,
)
else:
table.add_row(
matched,
name,
description,
filename,
)

console.print(to_out, table)
Expand Down
2 changes: 1 addition & 1 deletion pywhat/what.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main(text_input, rarity, include_tags, exclude_tags):
identified_output = what_obj.what_is_this(text_input)

p = printer.Printing()
p.pretty_print(identified_output)
p.pretty_print(identified_output, text_input)


class What_Object:
Expand Down

0 comments on commit 70def10

Please sign in to comment.