1

I'm writing a game using the curses library. I am trying to display some non-standard Unicode characters, and there I encountered a problem.

Let's say I want to display an Unicode tree character. Quick google renders something like this:

“” (U+1F332)

However, when I try to display that in my Python terminal, CMD or using curses a curses window, all I get is this:

In: u'\u1F332'
Out: 'ἳ2' 

Is that because the font I am using doesn't support this particular character? Is there a way of adding additional Unicode characters to the curses library?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Piotr
  • 39
  • 1
  • 5
  • Perhaps you omitted the call to `setlocale` (see [this](https://stackoverflow.com/questions/52429607/unicode-box-drawing-characters-not-printed-in-ruby) for example). – Thomas Dickey Oct 28 '18 at 17:53

1 Answers1

2

The escape sequence \u interprets the following four characters (in your case 1F33) as a 16 bits hexadecimal expression, which is not what you want. Since your code point does not fit in 16 bits you need the escape sequence \U and provide a 32 bits (eight characters long) hexadecimal expression.

In [1]: '\U0001F332'                                                            
Out[1]: ''

(I am guessing from your output that you are using python 3.)

You might also have issues with your terminal encoding and font, but your current code doesn't let you even get to that point.

Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56
  • Subtle. Thanks, I would've never figured that out on my own. The above works, although the actual character looks slightly different; I guess this is due to my font/display settings. I will play with it and report my findings. Also, it only displays in my Python IDE; curses only displays the default 'question mark' character - is that also due curses' to the font limitations? Is there a way to add the required character to curses? – Piotr Oct 28 '18 at 19:05
  • BTW, I'm using the same font for both CMD and Spyder (Consolas). – Piotr Oct 28 '18 at 19:13
  • @Piotr I think it is a limitation of windows cmd but it is hard to tell without a [mcve] and details about your OS and environment (and not having a windows box handy myself). I found [an answer in superuser SO](https://superuser.com/a/1197987) suggesting that cmd is unable to display such a character but you can another console like conemu. – Stop harming Monica Oct 28 '18 at 23:25