0

I am fairly new to coding but love Python and am trying to understand something as I've run into a specific issue I need solved!

To give an example for context -

I am currently trying to stylize a pyfiglet title (centered) as a colored gradient. There seems to be no way to do this ASIDE FROM:

https://github.com/wasi-master/gradient_figlet

However, this is a CLI module/tool and I have no idea how to implement it into my script. There is no documentation and I am used to being provided with examples such as:

import gradient-figlet

gradient_figlet("TEST HELLO")

To give a printed gradient text (figlet) result as gradient-figlet accomplishes when used in command line using:

python -m gradient_figlet YOUR_TEXT

Is this possible in general?

Any help would be appreciated.

On a side note - I'd really like to be able to center things in console if anyone has any tips :)

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
KEEP BUSY
  • 41
  • 5
  • 1
    _"On a side note - I'd really like to be able to center things in console if anyone has any tips :)"_ search for the relevant question, or [ask](/help/how-to-ask) your own if you don't find one that helps. Limit your posts to _one question_ please! – Pranav Hosangadi Jan 08 '23 at 22:33

2 Answers2

0

It doesn't look like gradient_figlet has a non CLI implementation. However you could use subprocess to run the CLI and capture the output and use it.

import subprocess

the_result = subprocess.run(['python', '-m', 'gradient_figlet', 'YOUR_TEXT'], stdout=subprocess.PIPE)

Let me know if this isn't what you are looking for!

  • Let me give it a shot! I’m just wondering - won’t using this print the result in black and white? We shall see! Let me know if you have any ideas on how to center it in console too! – KEEP BUSY Jan 08 '23 at 23:37
  • import subprocess the_result = subprocess.run(['python', '-m', 'gradient_figlet', 'YOUR_TEXT'], stdout=subprocess.PIPE) print(the_result) This does not work! – KEEP BUSY Jan 08 '23 at 23:43
  • https://imgur.com/a/cMD6DsW – KEEP BUSY Jan 08 '23 at 23:47
  • Anyone know how to get it to properly print with color and formatting? – KEEP BUSY Jan 09 '23 at 01:10
  • Sorry that didn't work how you expected. The stdout keyword makes it return bytes instead of strings. try this instead: subprocess.check_output('python -m gradient_figlet YOUR_TEXT', encoding='UTF-8') I suspect that this will still be black and white. – Travis Simmons Jan 09 '23 at 01:21
  • Yes I was LITERALLY just about to let you know that was the case. It formatted the ASCII properly, but alas it's still black and white... any idea on how to retain color? – KEEP BUSY Jan 09 '23 at 01:29
  • I have not a single clue. I would start here, and combine it with catching the output of figlet https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux – Travis Simmons Jan 13 '23 at 00:46
0

I spoke with the creator of the repo and he kindly updated the repo to support usage within a script!

https://github.com/wasi-master/gradient_figlet

Hope this helps someone!

KEEP BUSY
  • 41
  • 5