sepandhaghighi / art

🎨 ASCII art library for Python

Home Page:https://www.ascii-art.site

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tried `aprint("rand")` from docs and got warning "[Warning] 'rand' is not printable in this environment."

Pyroseza opened this issue · comments

Description

Tried aprint("rand") from docs README.md and got warning [Warning] 'rand' is not printable in this environment. seems more like an error cos I don't get any output other than the warning.

Steps/Code to Reproduce

from art import  *
aprint("rand")

Expected Behavior

one of the following at least

>>> aprint("butterfly") # print art
Ƹ̵̡Ӝ̵̨̄Ʒ 
>>> aprint("happy") # print art
 ۜ\(סּںסּَ` )/ۜ
>>> aprint("love_you",number=1,text="test")  # 2-part art
»-(¯`·.·´¯)->test<-(¯`·.·´¯)-« 
>>> aprint("random") # random 1-line art mode
'(っ◕‿◕)っ '
>>> aprint("rand")   # random 1-line art mode
't(-_-t) '

Actual Behavior

[Warning] 'rand' is not printable in this environment.

Operating System

Windows 10 Pro

Python Version

3.8.1

ART Version (Use : art.__version__)

4.4

@Pyroseza Hi
Would you please give us more information about your environment(CMD,PowerShell and ...)?

Hi @sepandhaghighi, I am using gitbash (mingw64)

It seems git bash does not support all 1-Line arts.
We will filter Non-ASCII arts for rand mode in a future release

Interesting... thanks for the feedback, looking forward to the future release

Hi there, I’ve just done some reading up and found that mingw does not start up in UTF-8 but it can be both configured in the settings and it can be configured in memory for the current session using an environment variable LANG='C.UTF-8'

My suggestion is to set this variable if it is not set, then output the characters, I don’t know if this will work for sure but more can be seen here: https://stackoverflow.com/a/36692549

I’ll be testing this shortly and confirm if it works or not, if not I will do a little more research on my side.

So bad news that did not work for me, looks like mingw64 (a.k.a. git bash) does not play nice when outputting unicode chars. I did confirm that it works great in powershell.

I found a solution but not the preferred solutio, it seems to be the way that python is launched without a UTF-8 encoding for IO, it launches windows' 'cp-1252'.

I found that if I set this particular environment variable PYTHONIOENCODING=utf-8 before running my script it works perfectly, if I try set it inside the script it does not work at all.

Here is my proof it works:

$ PYTHONIOENCODING=utf-8 py.exe -3 aprint.py
\(◑д◐)>∠(◑д◐)
$ PYTHONIOENCODING=utf-8 py.exe -3 aprint.py
(ᾢȍˬȍ)ᾢ ļ ļ ļ ļ ļ

This is where I found the solution:
https://stackoverflow.com/questions/4374455/how-to-set-sys-stdout-encoding-in-python-3

I still think there must be a way to set this programmatically from your lib... I'm sure of it, or at least something similar...

@Pyroseza
Thanks for your effort.
Changing PYTHONIOENCODING environment variable is not a stable solution, because it may effect other programs and also is not applicable in all environments.
I think the best solution is filtering Non-ASCII 1-line arts for rand mode.