lemonade-command / lemonade

Lemonade is a remote utility tool. (copy, paste and open browser) over TCP.
MIT License
620 stars 54 forks source link

Unable to handle utf-8 #26

Open themadsens opened 7 years ago

themadsens commented 7 years ago

It seems that lemonade cannot handle utf-8 in and out of the clipboard. At least on MacOS.

As long as lemonade is used for both directions it seems OK, but using pbcopy or the system 'Copy' or 'Paste' in conjunction does not work

image

OS data according to screenfetch OS: 64bit Mac OS X 10.12.6 16G29 Kernel: x86_64 Darwin 16.7.0

In binary

[fmmbp thm-dotfiles]$ echo 'Blåbærgrød' | pbcopy
[fmmbp thm-dotfiles]$ pbpaste | hexdump -C
00000000  42 6c c3 a5 62 c3 a6 72  67 72 c3 b8 64 0a        |Bl..b..rgr..d.|
0000000e
[fmmbp thm-dotfiles]$ lemonade paste | hexdump -C
00000000  42 6c 8c 62 be 72 67 72  bf 64 0a                 |Bl.b.rgr.d.|
0000000b
[fmmbp thm-dotfiles]$ echo 'Blåbærgrød' | hexdump -C
00000000  42 6c c3 a5 62 c3 a6 72  67 72 c3 b8 64 0a        |Bl..b..rgr..d.|
0000000e
[fmmbp thm-dotfiles]$ echo 'Blåbærgrød' | lemonade copy
[fmmbp thm-dotfiles]$ pbpaste | hexdump -C
00000000  42 6c e2 88 9a e2 80 a2  62 e2 88 9a c2 b6 72 67  |Bl......b.....rg|
00000010  72 e2 88 9a e2 88 8f 64  0a                       |r......d.|
00000019
[fmmbp thm-dotfiles]$ lemonade paste | hexdump -C
00000000  42 6c c3 a5 62 c3 a6 72  67 72 c3 b8 64 0a        |Bl..b..rgr..d.|
0000000e
mattn commented 5 years ago

Go's runtime is not affected by the locale. So if the binary is changed, there migit be caused by pbcopy or pbpaste. I guess that it is the locale of the server is C or latin-1.

jinmiaoluo commented 5 years ago

Hey, guys. I suffer the same problem. If you use Supervisord as your local process manager you should add some environment variables into supervisord.ini to fix the encoding problem. example:

[supervisord]
...
environment=LC_ALL=en_US.UTF-8,LANG=en_US.UTF-8

result: https://asciinema.org/a/u03PdoBOdySt4kiGvz0sYWSuT

yuchanns commented 2 years ago

For people who uses MacOS as the server and manage the process by launchctl, you may want to add a environment.plist in ~/Library/LaunchAgents with the content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>environment</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>
        <!-- Add locale category for native language -->
        <!-- For me, it's zh-CN.UTF-8 -->
        launchctl setenv LANG zh_CN.UTF-8
        launchctl setenv LC_ALL zh_CN.UTF-8
    </string>

  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

Then load it by launchctl load environment.plist. It works now.