Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode characters not correctly printed with cow image #9

Open
Nevon opened this issue Oct 4, 2016 · 4 comments
Open

Unicode characters not correctly printed with cow image #9

Nevon opened this issue Oct 4, 2016 · 4 comments

Comments

@Nevon
Copy link

Nevon commented Oct 4, 2016

If I use cowsay with an image that has been converted to a cowfile and a string containing 4-byte characters, they are output incorrectly:

➜ cowsay -f cows/Eevee.cow -- "こんにちは世界"
 _______________________
< ������� >
 -----------------------
           \
            \
             \
              \
            ▄▄▄
▄▄▄▄ ▄▄▄▄ ▄ ▄
  ▄    ▄▄▄▄▄▄▄▄
▀▄   ▄▄▄▄      ▄
  ▀ ▄  ▄▄ ▄▄   ▄
  ▄▄    ▄▄▄▄▄▄▄▄▄
    ▄▄▄▄▄    ▄ ▄▀
   ▀▀  ▀▄▄▄▄▄▄▀
        ▀▄▄▀▀

screen shot 2016-10-04 at 14 49 04

If I remove binmode STDOUT, ":utf8"; from the cowfile, the message is output correctly, but instead we get a warning from perl:

➜ cowsay -f cows/Pikachu.cow -- "こんにちは世界"
 _______________________
< こんにちは世界 >
 -----------------------
Wide character in print at /usr/local/bin/cowsay line 71.
           \
            \
             \
              \
  ▄▄          ▄▄
▄▄ ▄▄▄▄▄▄     ▄▄▄
▀▄▄  ▄▄  ▄▄▄ ▀▄▄ ▄
  ▀▄▄  ▄▄▄▄ ▄▄▄  ▄▄▄
   ▄▄ ▄▄▀ ▄ ▄▄▄▄  ▄▄▄
   ▀▄ ▄▄▄  ▄▄▄▄ ▄▄▄▄▀
    ▄▄▄▄▄▄  ▄▄ ▄▄▄▄▄▀
     ▀▄▄  ▄▄▄▄  ▄
      ▀▄    ▄▄▄▀
        ▀▄▄▀

screen shot 2016-10-04 at 14 48 08

This is using, for example, this file:

binmode STDOUT, ":utf8";
$the_cow =<<EOC;
           $thoughts
            $thoughts
             $thoughts
              $thoughts
\e[49m           \e[48;5;236m \e[38;5;179m\N{U+2584}\N{U+2584}\e[49m\e[38;5;236m\N{U+2584}
\N{U+2584}\e[48;5;236m\e[38;5;230m\N{U+2584}\e[49m\e[38;5;236m\N{U+2584}\N{U+2584}\e[48;5;236m \e[38;5;185m\N{U+2584}\N{U+2584}\e[49m\e[38;5;236m\N{U+2584}\N{U+2584} \N{U+2584}\e[48;5;236m \e[48;5;179m\e[38;5;137m\N{U+2584}\e[48;5;240m \e[48;5;179m \e[48;5;236m \e[49m
\e[48;5;236m \e[48;5;230m \e[38;5;185m\N{U+2584}\e[48;5;137m \e[48;5;239m \e[48;5;179m \e[48;5;240m \e[48;5;185m\e[38;5;240m\N{U+2584}\e[48;5;137m\e[38;5;179m\N{U+2584}\e[48;5;236m\e[38;5;240m\N{U+2584}\e[38;5;185m\N{U+2584}\e[48;5;185m\e[38;5;179m\N{U+2584}\e[48;5;239m\e[38;5;185m\N{U+2584}\e[38;5;179m\N{U+2584}\e[48;5;240m\e[38;5;239m\N{U+2584}\e[48;5;236m \e[49m
\e[38;5;236m\N{U+2580}\e[48;5;185m\N{U+2584}\e[48;5;137m   \e[48;5;239m\e[38;5;240m\N{U+2584}\e[48;5;179m\e[38;5;239m\N{U+2584}\e[48;5;240m\e[38;5;179m\N{U+2584}\e[38;5;137m\N{U+2584}\e[48;5;179m      \e[48;5;240m\e[38;5;231m\N{U+2584}\e[48;5;236m \e[49m
  \e[38;5;236m\N{U+2580}\e[48;5;236m \e[48;5;240m\e[38;5;137m\N{U+2584}\e[48;5;137m \e[48;5;240m \e[48;5;239m\e[38;5;185m\N{U+2584}\e[48;5;179m\e[38;5;240m\N{U+2584} \e[48;5;240m\e[38;5;236m\N{U+2584}\e[48;5;137m\e[38;5;231m\N{U+2584}\e[48;5;179m   \e[48;5;236m\e[38;5;179m\N{U+2584} \e[49m
  \e[38;5;236m\N{U+2584}\e[48;5;236m\e[38;5;137m\N{U+2584}\e[48;5;137m \e[48;5;240m \e[48;5;185m  \e[48;5;240m\e[38;5;230m\N{U+2584}\e[48;5;137m\e[38;5;240m\N{U+2584}\e[48;5;236m\e[38;5;137m\N{U+2584}\e[48;5;240m\N{U+2584}\e[48;5;179m\N{U+2584}\e[38;5;240m\N{U+2584}\e[48;5;173m\e[38;5;95m\N{U+2584}\e[48;5;236m\e[38;5;230m\N{U+2584}\e[49m\e[38;5;236m\N{U+2584}
  \e[48;5;236m \e[48;5;137m \e[38;5;240m\N{U+2584}\e[48;5;240m\e[38;5;236m\N{U+2584}\e[48;5;239m\N{U+2584}\e[48;5;185m\e[38;5;240m\N{U+2584}\e[48;5;230m\e[38;5;185m\N{U+2584} \e[48;5;185m \e[48;5;230m  \N{U+2584} \e[38;5;236m\N{U+2584}\e[49m\N{U+2580}
   \N{U+2580}\N{U+2580}  \N{U+2580}\e[48;5;137m\N{U+2584}\e[48;5;95m\e[38;5;137m\N{U+2584}\e[48;5;230m\e[38;5;239m\N{U+2584}\e[48;5;185m\N{U+2584}\e[38;5;137m\N{U+2584}\e[48;5;239m\e[38;5;236m\N{U+2584}\e[49m\N{U+2580}
        \N{U+2580}\e[48;5;137m\N{U+2584}\e[48;5;179m\N{U+2584}\e[49m\N{U+2580}\N{U+2580}\e[39m

EOC
@possatti
Copy link

possatti commented Oct 6, 2016

Why do you use -- when invoking pokemonsay?

@Nevon
Copy link
Author

Nevon commented Oct 6, 2016

Usage: cowsay [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...]

It separates the options from the arguments, so that you can do, for example:

➜  cowsay -- -f
 ____
< -f >
 ----
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

@possatti
Copy link

Hmm, interesting. I am using version 3.03. But both in the man page and the --help option, mine doesn't mention the --:

Usage: cowsay [-bdgpstwy] [-h] [-e eyes] [-f cowfile] [-l] [-n] [-T tongue] [-W wrapcolumn] [message]

Thanks for letting me know. o/

@rossy
Copy link
Owner

rossy commented Nov 3, 2016

I'm not quite sure how to fix this. Getting cowsay to do proper Unicode output was a pain, but I thought that binmode line fixed it. (I am not a Perl expert.) What's the output of locale on your machine?

@possatti Yeah, that -- thing is a common convention in programs that do GNU-style option parsing. It looks like cowsay gets this behaviour from Perl's Getopt::Std.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants