possatti / pokemonsay

"pokemonsay" is like "cowsay" but for pokémon.
MIT License
499 stars 53 forks source link

Unicode characters are not supported #3

Open Nevon opened 7 years ago

Nevon commented 7 years ago
/ # ./root/bin/pokemonsay фывафва
 ________________ 
< ÑÑваÑва >
 ---------------- 
           \
            \
             \
              \
        ▄▄▄▄
       ▄▄  ▄▄▄ 
   ▄▄▄▄▄▄▄ ▄   
 ▄▄▄▄ ▄▄ ▄ ▄▄▄  ▄▄▄▄▄
 ▀ ▄  ▄▄▄ ▄▄ ▄▄▄▄▄   
  ▄▄▄▄▄▄▄ ▄▄▄ ▄▄▄   ▄▄
 ▄▄▄ ▄ ▄▄ ▄  ▄▄▄ ▄▄ ▄▄▄ 
  ▄▄▄▄▄ ▄ ▄ ▄▄ ▄▄ ▄ ▄ ▄▀
  ▀▀▀    ▄  ▀▄▄▄  ▄▄▄▀
       ▀▄▄▄▀    ▀▀▀

Rhyhorn
screen shot 2016-10-04 at 13 22 20
xaviervia commented 7 years ago

We tested this in docker with Alpine linux. echo and cowsay print the unicode characters just fine, so the issue seems to be coming from pokemonsay.

Great project btw, love it ❤️

Nevon commented 7 years ago

Cross-posted this issue upstream, since it looks like the issue is in rossy/img2xterm#9

possatti commented 7 years ago

Thanks for the support guys.

Funny thing, I am Brazilian but I have only tested with English text so far. But it's just like @Nevon said, it looks like an issue with img2xterm.

possatti commented 7 years ago

I've been thinking about this and I think there's a way around the problem. It's not the most elegant solution, but I could remove binmode STDOUT, ":utf8"; from all cowfiles and pipe the output of cowsay to a sed process which will remove that warning line.

I went on to experiment with that. I removed the binmode thing and it worked. I've put the thing back again expecting it to not work... and it also worked. Suddenly I don't understand anything anymore, but mine is working with a clean repo. It's like I have done nothing, but it is working.

screenshot from 2016-10-06 08-54-26

I wish I've noticed what happened and I would come up with a solution, but I don't.

xaviervia commented 7 years ago

sed sounds like a beautiful solution to me. No need for more if it works. :shipit:

possatti commented 7 years ago

Guys, could you try the branch unicode. I think there is no need to install, just clone the repo and do ./pokemonsay.sh "こんにちは世界" a few times. I might have fixed the problem.

If you can, please test the master branch as well. Nothing changed on master, but I'm puzzled that I can't reproduce the problem anymore.

I'm sorry it took so long for me to take a look at this. It's my last year in college and things are really tough. xD

Nevon commented 7 years ago
screen shot 2016-10-16 at 08 16 26

At first I figured maybe it was an issue with your expression, so I made one that might be a little more robust, but it's also failing. However, it is matching the text normally, so there's something fishy.

screen shot 2016-10-16 at 08 23 52

However, it works with a plain non-ansi nonsense cowfile:

screen shot 2016-10-16 at 08 26 36

Then I thought that maybe the warning was in stderr or something, so I tried combining the streams before doing the sed, but that didn't work either. Super weird.

Having never written Perl in my life, I have no idea if the following is correct, but I think the binmode(STDOUT, ":utf8"); should stay. The files are encoded as us-ascii, which is a subset of utf8, so we are expecting the output to be utf8. So I went the other direction and modified cowsay to basically tell it that anything and everything is utf8 and should be treated as such:

use utf8;
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";
binmode STDIN,  ":utf8";

But nope...

screen shot 2016-10-16 at 09 25 53

I'm sorry it took so long for me to take a look at this. It's my last year in college and things are really tough. xD

Don't kill yourself over it, man. It's a silly way to have pokemon in your terminal, not a cure for cancer.

lookoutldz commented 2 years ago

6 years gone. Did you solve the problem?

JasonLamv-t commented 3 weeks ago

6 years gone. Did you solve the problem?

8 years now. :)