From 3814db460fca6d23990da2da46b6ead8cd249cdc Mon Sep 17 00:00:00 2001 From: Benex254 Date: Sun, 11 Aug 2024 21:00:38 +0300 Subject: [PATCH] feat(cli): default print_image function to use icat --- fastanime/cli/utils/print_img.py | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/fastanime/cli/utils/print_img.py b/fastanime/cli/utils/print_img.py index 68dd471..836ab56 100644 --- a/fastanime/cli/utils/print_img.py +++ b/fastanime/cli/utils/print_img.py @@ -5,20 +5,23 @@ import requests def print_img(url: str): - executable = shutil.which("chafa") - curl = shutil.which("curl") - # curl -sL "$1" | chafa /dev/stdin + """helper funtion to print an image given its url - if executable is None or curl is None: - print("chafa or curl not found") - return + Args: + url: [TODO:description] + """ + if EXECUTABLE := shutil.which("icat"): + subprocess.run([EXECUTABLE, url]) + else: + EXECUTABLE = shutil.which("chafa") - res = requests.get(url) - if res.status_code != 200: - print("Error fetching image") - return - img_bytes = res.content - if not img_bytes: - print("No image found") - img_bytes = subprocess.check_output([curl, "-sL", url]) - subprocess.run([executable, url, "--size=15x15"], input=img_bytes) + if EXECUTABLE is None: + print("chafanot found") + return + + res = requests.get(url) + if res.status_code != 200: + print("Error fetching image") + return + img_bytes = res.content + subprocess.run([EXECUTABLE, url, "--size=15x15"], input=img_bytes)