hykilpikonna / hyfetch

🏳️‍🌈 🏳️‍⚧️ Neofetch with LGBTQ+ pride flags!
MIT License
1.15k stars 90 forks source link

Cannot render ascii art with certain unicode characters on Windows #293

Closed luna-1024 closed 1 month ago

luna-1024 commented 1 month ago

Describe the bug

Due to most file reads/write in the code base explicitly specifying utf-8 encoding, it seems likely that unicode ascii art support on Windows may have already been intended.

However, in Windows, it is not currently possible to use unicode ascii art (except it works on the qwqfetch backend). For example setting the distro to {Fedora_unicode, NixOS, Manjaro, or unicodearch} in hyfetch.json results in an encoding error. If this worked, we could for example have a unicode Windows ascii art with block characters, or otherwise fully support unicode for the --ascii-file arg on Windows.

Expected behavior

Unicode ascii art is rendered in Windows terminal, since it can display utf-8 characters. (see this post).

Screenshots

On Windows, setting the distro to unicodearch results in this error:

PS C:\Users\Luna\code\hyfetch> hyfetch
Error: 'charmap' codec can't encode character '\u2584' in position 78: character maps to <undefined>
Traceback (most recent call last):
  File "C:\Users\Luna\code\hyfetch\hyfetch\main.py", line 451, in run
    neofetch_util.run(asc, config.backend, config.args or '')
  File "C:\Users\Luna\code\hyfetch\hyfetch\neofetch_util.py", line 303, in run
    return run_neofetch(asc, args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Luna\code\hyfetch\hyfetch\neofetch_util.py", line 347, in run_neofetch
    path.write_text(asc)
    ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Luna\AppData\Local\Programs\Python\Python312\Lib\pathlib.py", line 1049, in write_text
    return f.write(data)
           ^^^^^^^^^^^^^
  File "C:\Users\Luna\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u2584' in position 78: character maps to <undefined>
PS C:\Users\Luna\code\hyfetch>

Config file

Please paste the content of ~/.config/hyfetch.json below:

{
    "preset": "transgender",
    "mode": "rgb",
    "light_dark": "dark",
    "lightness": 0.65,
    "color_align": {
        "mode": "horizontal",
        "custom_colors": [],
        "fore_back": null
    },
    "backend": "neofetch",
    "args": null,
    "distro": "unicodearch",
    "pride_month_shown": [],
    "pride_month_disable": false
}

Additional context

The error occurs because the temp ascii art file writes (1, 2) is defaulted to Windows-1252 encoding.

Backends