mobile-shell / mosh

Mobile Shell
https://mosh.org
GNU General Public License v3.0
12.44k stars 727 forks source link

UTF-8/color problems under cygwin #315

Closed JasonGross closed 11 years ago

JasonGross commented 11 years ago

When I compile https://github.com/keithw/mosh/pull/96 under cygwin, mosh seems to mess up on colors. When I :show colors in barnowl in screen on linerva, I get https://dl.dropbox.com/u/11313181/Temp/barnowl-colors.png.

keithw commented 11 years ago

I can't vouch that your Cygwin terminal indeed handles 256color escape sequences (what TERM does it advertise?), but we can try to break this apart.

Can you run this script (a) directly in your terminal (b) in your terminal via mosh (c) in your terminal via screen (d) with the script-in-screen-in-mosh in your terminal?

http://scie.nti.st/dist/256colors2.pl

You can compare to a real xterm to see what you should be seeing.

JasonGross commented 11 years ago

Ack, sorry, I forgot to mention that the cygwin-bundled ssh works fine (displays colors correctly).

cygwin advertises TERM=cygwin, linerva advertises TERM=xterm, and my screen advertises TERM=screen-256color-bce. I'll go run the script now.

JasonGross commented 11 years ago

Ok, https://dl.dropbox.com/u/11313181/Temp/256colors.png upper left: local bash (looks identical to ssh, not in screen) lower left: screen in ssh upper right: mosh, no screen lower right: mosh, screen

Edit: sorry for the lines. If I make the two mosh terminals wider (as wide as windows lets me make terminals), I get https://dl.dropbox.com/u/11313181/Temp/256colors-2.png

keithw commented 11 years ago

Yeah, the basic problem here is that your terminal doesn't support the 256color escape sequences (and the TERM=cygwin entry doesn't advertise them either -- it only supports 8 colors). TERM=xterm is also an 8-color terminal (which is what mosh advertises when its outer terminal is 8-color capable).

Here's my guess: at some point you edited your .screenrc to tell it to override the terminfo database, and you told it that "xterm" supports 256colors. You also probably told screen to advertise a 256color-capable terminal itself.

When you run screen with TERM=cygwin, it sees that you're on an 8color terminal and posterizes the incoming 256color escape sequences down to 8 colors.

But when you run screen with TERM=xterm, it uses the "overriding" setting in your .screenrc and DOESN'T translate the sequences. It just hands them off to Mosh. Mosh then passes them along to your outer terminal, which doesn't support them either.

(Mosh actually used to posterize them itself, but we stopped this because it led to more confusion.)

(What does barnowl do when you run it directly in Mosh? My assumption is that Mosh is advertising TERM=xterm, so I think this might work better.)

The solution here is probably one of (a) remove these entries from your .screenrc that tell it to override xterm's entry and/or (b) use a 256color capable terminal. When you use an xterm or gnome-terminal, you should have the terminal export TERM=xterm-256color, instead of trying to override the xterm setting.

(See this comment for more context: https://github.com/keithw/mosh/issues/3#issuecomment-4515363)

JasonGross commented 11 years ago

BarnOwl in mosh, without screen, gives https://dl.dropbox.com/u/11313181/Temp/barnowl.png and https://dl.dropbox.com/u/11313181/Temp/barnowl-2.png

My ~/.screenrc file is

altscreen on
# Erase background with current bg color
defbce on
# Advertise 256 color support to inner applications
term screen-256color-bce

I think I put in the "bce" part to work around an 'underlining in barnowl with 256 colors' bug. If I ssh in with TERM=xterm-256colors, screen just gives me TERM=screen. Is there a better way to get screen to give me more colors when the outer terminal gives me more colors?

keithw commented 11 years ago

I don't know how to make screen adjust its TERM based on the number of colors in the outer terminal. It may be possible but you may have to recompile screen.

Based on that screenshot, I don't think your Cygwin terminal supports UTF-8 either. You are probably going to be happier just switching to a better terminal, e.g. PuTTY's terminal or something else. We do have some users on Cygwin but I don't know what they use. You might email the Cygwin package maintainer (rurban at x-ray.at) and see what he thinks.

JasonGross commented 11 years ago

./configure did give me an error about IUTF8 not working/not being found.

Does PuTTY have a stand-alone terminal? I've found mentions to pterm, but, AFAICT, that exists only on linux/unix.

Also, PuTTY seems to have a bit of trouble with barnowl not in screen; it shows me https://dl.dropbox.com/u/11313181/Temp/barnowl-putty.png

keithw commented 11 years ago

I dunno much about Cygwin, but I think the cool kids (that are not running Linux in a VM) are running KiTTY with the Puttycyg patch, or just Puttycyg.

JasonGross commented 11 years ago

Puttycyg works. Thanks!

JasonGross commented 11 years ago

However, using Puttycyg (I haven't tried KiTTY), I need to manually set the remote TERM to xterm-256color. I have it set locally to xterm-256color (and mosh-client -c gives me 256), and when I use ssh, TERM is xterm-256color, but when I mosh jgross@linerva.mit.edu --server='athrun mosh_project mosh-server', TERM is xterm.

Edit: This is fixed/addressed by https://github.com/keithw/mosh/pull/96#issuecomment-7804069

keithw commented 11 years ago

Glad you got it working.