visit1985/mdp

UTF-8 mac os x

jacoelho opened this issue · 8 comments

I cannot see UTF-8 chars correctly on yosemite:
screen shot 2015-05-21 at 11 04 54

echo $TERM
xterm-256color
locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
otool -L ./mdp
./mdp:
    /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

I think that's a font issue. How does it look when you cat the file?

sure:

screen shot 2015-05-22 at 13 35 25

I really have no clue where to start on that. On Linux it works perfectly. What terminal emulator are you using? Can you try urxvt?

skade commented

This is definitely not related to the terminal emulator. It works in iTerm 2 on OS X when running mdp in a Linux VM and SSHing in.

I do have the same problem when running mpd on the host.

@visit1985
Yes, I have this problem, too.
I also try to compile and link mdp with ncursew, but nothing changed.

env LDFLAGS=-L/usr/local/opt/ncurses/lib CPPFLAGS=-I/usr/local/opt/ncurses/include make

/Applications/Xcode.app/Contents/Developer/usr/bin/make  -C src
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o cstack.o cstack.c
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o cstring.o cstring.c
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o main.o main.c
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o markdown.o markdown.c
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o parser.o parser.c
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o url.o url.c
cc -O3 -Wall -I/usr/local/opt/ncurses/include -I../include  -c -o viewer.o viewer.c
cc src/cstack.o src/cstring.o src/main.o src/markdown.o src/parser.o src/url.o src/viewer.o -lncursesw -L/usr/local/opt/ncurses/lib -o mdp
otool -L mdp
mdp:
    /usr/local/opt/ncurses/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

Still can't display any UTF-8 chars.

@justmao945 I had the same issue on OpenBSD, but the following patch fixed it.
Could you please test it?

diff --git a/src/main.c b/src/main.c
index 9920f38..e95bc04 100644
--- a/src/main.c
+++ b/src/main.c
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
     }

     // set locale to read and display UTF-8 correctly in ncurses
-    setlocale(LC_CTYPE, "en_US.UTF8");
+    setlocale(LC_CTYPE, "");

     // open file or set input to STDIN
     char *file = NULL;

The empty string "denotes the native environment", according to man setlocale.

Alternatively, a more hacky solution:

diff --git a/src/main.c b/src/main.c
index 9920f38..3009f7a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
     }

     // set locale to read and display UTF-8 correctly in ncurses
-    setlocale(LC_CTYPE, "en_US.UTF8");
+    setlocale(LC_CTYPE, "en_US.UTF-8");

     // open file or set input to STDIN
     char *file = NULL;

I assume this works because OpenBSD has no locale named UTF8, only UTF-8 (note the lack of a hyphen in the former):

/usr/share/locale $ ls
ARMSCII-8   CP866       ISO8859-13  ISO8859-2   ISO8859-5   ISO8859-9   KOI8-U
CP1251      ISO8859-1   ISO8859-15  ISO8859-4   ISO8859-7   KOI8-R      UTF-8

@pyrohh That's great! Both of them work well on OS X. You can make a pr now 😄

You can make a pr now

Sure thing, please see #91.