1

relatively new python programmer here. I'm coding a program on windows 10 that uses the climage module to display pictures in the terminal using unicode characters (yes, it has to be displayed in the terminal), my code looks something like this.

print(climage.convert("cat.png", is_256color=True, is_truecolor=False, 
    is_unicode=True))

The issue with this is that while my IDE (pycharm) displays the unicode characters just fine when I click on and run the python file it just spits back a bunch of garbage at me.

[38;5;16m▄←[48;5;16m←[38;5;16m▄←[48;5;16m←[38;5;16m▄←[48;5;16m←[38;5;16m▄←[48;5;16m←[38;5;16m▄←[48;5;16m←[38;5;16m▄←[48;5;16m←[38;5;16m▄←

This kind of stuff repeated over and over and over. I'm assuming they're its best attempt at displaying unicode characters with whatever limitation it has that causes this but I'm not very familiar with unicode. So what I'm asking is, is there a way to run this with it actually displaying the unicode characters as they're supposed to be?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Veo
  • 11
  • 2
  • 2
    That's not just Unicode, those are escape sequences. Probably something related to xterm escape sequences. Most terminal emulators should be able to display that correct, if configured correctly). Most IDEs have very limited terminal emulators (to phrase it politely). – Joachim Sauer Sep 18 '21 at 19:56
  • Which operating system? – tdelaney Sep 18 '21 at 20:27
  • @JoachimSauer Thanks for the response, could you elaborate on what exactly all that means? What you said hasn't really explained to me how to make my terminal display (whatever those characters are, your comment thoroughly confused me). I am somewhat new to programming this kind of thing so any extra information you can give would be very helpful :) – Veo Sep 18 '21 at 20:39
  • @tdelaney sorry, rookie mistake. Windows 10 :) – Veo Sep 18 '21 at 20:40
  • I don't have windows up at the moment. Does it work if you run the .py file from a cmd console? Likely not as clicking on it basically brings up a console. But curious anyway. – tdelaney Sep 18 '21 at 20:42
  • @tdelaney no, i tried that as well and it did the same thing :/ – Veo Sep 18 '21 at 20:44
  • I searched "python module vt100 to windows terminal" (those are ansi or vt escape sequences) and got hits like for instance [pyte](https://pypi.org/project/pyte/) but have no idea which are good. – tdelaney Sep 18 '21 at 20:51
  • @tdelaney i've tried a number of modules that say they put in support for these ansi escape sequences (I tried stuff like pyte and xterm which some other people had mentioned but absolutely could not wrap my head around it) and now instead of printing gibberish, it now just prints multiple lines of just white characters instead of my image. progress I suppose, but I'm not sure where to go form here. – Veo Sep 18 '21 at 21:23
  • Ouch! The vt/ansi escape sequences are adding the color. It sounds like these tools are just stripping them instead of true emulation. Windows has a linux subsystem, maybe that's the next best step. – tdelaney Sep 18 '21 at 21:26
  • Does this answer your question? [Enable ANSI sequences in windows terminal](https://stackoverflow.com/questions/64919350/enable-ansi-sequences-in-windows-terminal) – Thomas Dickey Sep 20 '21 at 08:38

2 Answers2

0

I gathered a bunch of links that might help:

The last one seems to be the most relevant since it's a python question as well.

Basically They suggest running os.system('') before running your code to activate cmd vt100 emulation.

Almog-at-Nailo
  • 1,152
  • 1
  • 4
  • 20
0

Use os.system('') at the start of your code Remember to import os module using import os

Like,

# Activating vt100 emulation on cmd
os.system('')

# Your code
print(climage.convert("cat.png", is_256color=True, is_truecolor=False, 
    is_unicode=True))

Then cmd will activate the vt100 emulation and show you the colors.

MaxMouse
  • 5
  • 1
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 14 '22 at 20:47