You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
urxvt (aka rxvt-unicode) sends CSI7~ and CSI8~ for Home, End respectively.
With TERM=rxvt-unicode, bash will interpret these correctly and jump to the beginning/end of the line.
Screen sets TERM=screen and translates them to CSI1~ and CSI4~, which bash also understands.
But Mosh sets TERM=xterm and does no translation, so bash gets confused.
If I tell urxvt (by X resource) to send CSI1~ then my local bash is confused. If I tell it to use CSIH and CSIF, the Xterm codes, then most things work, but Barnowl doesn't recognize these codes (which could be a Barnowl bug).
The correct way to solve this may be to place a full UTF8Parser state machine at the client, interpret all the CSIs, and translate "khome" and "kend" (and all the other "k" capabilities) from the user's terminal to xterm sequences.
This seems both like a pain and likely to introduce unpleasantness side effects, but there may be no way around it...
I thought about this a little more, and I haven't figured out a way to do it that doesn't have the client start depending on the timing of input bytes, which I hate to do.
If we want to capture Putty's ESC [ 1 ~ (khome) and turn it into xterm's ESC O H (khome), we basically have to eat ESC [ and then observe the rest of the escape sequence before printing O H. But I'm not comfortable just eating ESC [ and sitting there indefinitely without printing the [ . On the other hand, I hate the idea of a timeout.
On the third hand, maybe the least bad path is a timeout -- but only when the outer terminal requires this kind of translation (so not for TERM=xterm).
I had this problem too. Manully exporting TERM=rxvt-unicode-256color on server after connecting makes Home/End keys behave well in applications, but unfortunately not that shell.
Will there be any problem if mosh just passes the client $TERM to server?
Passing TERM to the server is not the right approach; see my comment #446 (comment).
This needs to be done via translation on the client side in order for the client and server to agree about the state of the terminal at all times. Probably the most clever approach would be to read the client’s terminfo entry and learn the translation automatically from that (like ncurses does).
I don't think this issue (about rxvt cursor-key sequences sent from the terminal to the application) is related to colors (sequences sent from the application to the terminal). Your comment is probably better on issue #557 .
All I know is that when I edit src/frontend/mosh-server.cc and s/xterm-256color/rxvt-unicode-256color/ all my home/end issues go away and I don't notice any further issues :) . I guess I need to get the remote system to understand xterm-256color as the "right" solution.
I connect with mosh using both xterm and rxvt-unicode and the different escape codes completely hose things. I think that this really needs some solution. I would be happy with either parsing the escape codes or causing the server to be run with the correct TERM...
mosh incorrectly sets $TERM as xterm-256color while ssh correctly sets it as rxvt-unicode-256color I have my .zshrc set up with escape sequence hackery to get around this, but it shouldn't be necessary at all.
The workaround I'm using for the time being in my .zshrc is checking if TERM is set to xterm*, changing it to rxvt, then doing exec zsh. The exec zsh replaces the current shell with a new instance so the shell itself inherits the TERM variable.
case $TERM in
xterm*)
export TERM=rxvt
exec zsh
;;
rxvt-unicode-256color*)
export TERM=rxvt
;;
esac
If you try to do something similar, it's absolutely critical that the exec can't get executed on a subsequent run of zsh, or your ability to login via that shell will be completely hosed. Just looking at it causes me anxiety. :)
Much less insane than what I was doing above. In my first attempt to set the keybindings, I had it in my head to use "^[[1~" and "^[[4~", which was not correct. Thanks.
@hhirsch in case it helps: I am using mosh like this:
screen mosh me@myserver tmux attach
And my ~/.screenrc has:
escape ""
startup_message off
Which is okay since I normally use tmux for everything. I did not edit any other configuration files.
With this setup I have not yet encountered any issues. I'm using mcabber and irssi inside that tmux session on myserver where I frequently use keys like Home/End and PageUp/PageDown.
@josch Well to me this seems like too much trouble to make a square wheel turn.
ssh does not have bugs like this so I just stick to it. If basic stuff like this is broken who knows what else is. I'll try again in 10 years when this issue is fixed.
I must also comment that this certainly does not work for me, even using the `screen' trick described above. In particular, I encounter #161. Why does mosh have to emulate a terminal? Why can't it just pass back and forth the byte sequences produced by and for the user's actual terminal?
@tsmithe Mosh relies on a deep understanding of the terminal input and display for its latency reduction tricks. (“But I have a fast network and I don’t need those!” Great, go use SSH then. “But I want Mosh’s automatic roaming!” Well, I sympathize—there’s a place in the world for a version of SSH with just the addition of automatic roaming. But Mosh is not that and cannot reasonably be made into that.)
The screen-in-urxvt workaround does fix the Home/End keys as advertised. It does not help with Ctrl-Arrow keys, but I think that is a screen bug: Ctrl-Arrow keys do not work in screen-in-urxvt even when Mosh is not involved.
Interesting; I did not expect that mosh's features depended on such hidden complexity! Thanks for your reply.
I did respect the order for the workaround commands, but with no luck. I will have to investigate more deeply. Should you have any debugging suggestions, I would be glad to hear them, but I suspect I have not provided sufficient detail for that (simply due to ignorance..).
Although I can speculate, I am not completely sure why this is -- and why this works whilst other suggestions do not -- but I hope this might be helpful to others.
I have found that, with the following .emacs snippet, the xtermcompat hack is unnecessary if I use the screen workaround described above (again, I use tmux for everything, so that's fine). But without this .emacs snippet, I do not get the correct remote behaviour either with the xtermcompat hack, or with the screen workaround. Note that, in both cases (xtermcompat hack, and screen workaround), I find this snippet to be necessary to get the correct remote behaviour in emacs. I am not sure why emacs (24.5.1) needs it!
I do not know what the 'select' key is. Running 'read' at the remote end gives me ^[[4~, which is just what I get locally, where there is no `select' problem!
I will add further mappings as and when I find or need them. In particular, I still do not get the right behaviour (seemingly in any case so far!) if I have a local tmux session, with a nested remote tmux session in mosh.
Fundamentally, it just seems like mosh doesn't interpret urxvt I/O correctly, but it does a better job with a client-side tmux session, which in turn does a reasonable job with urxvt... This means that I have a passably working set-up, and can therefore enjoy the many benefits of mosh. These benefits comfortably outweigh the frustrations of these hacks, for now!
EDIT: The solution (for now..) for the nested remote tmux problem was to turn on the xterm-keys tmux option remotely.
Little workaound for me was installing rxvt-unicode (which I'm using on my client too) and then putting export TERM=rxvt-unicode into the ~/.bashrc of the user I'm connecting to.
Works for me, even su into another account.
EDIT: before putting that into your bashrc, you can just run echo $TERM to see that it says something xterm. Then running export TERM=rxvt-unicode might fix it. If so, you can put it into your bashrc.
I switched back from tmux to screen for a while (not quite knowing which part of the chain of terminal emulators broke this) because screen apparently translates rxvt keys to xterm keys, while tmux does not. Now I'm back to tmux (because it's just so much nicer) and I would really appreciate if there was a fix for this. Setting TERM=rxvt-unicode-256color for now because it seems like a viable workaround.
Activity
keithw commentedon Apr 17, 2012
The correct way to solve this may be to place a full UTF8Parser state machine at the client, interpret all the CSIs, and translate "khome" and "kend" (and all the other "k" capabilities) from the user's terminal to xterm sequences.
This seems both like a pain and likely to introduce unpleasantness side effects, but there may be no way around it...
kmcallister commentedon May 8, 2012
If we do client-side parsing for #101, maybe we can do this too.
keithw commentedon Dec 7, 2012
I thought about this a little more, and I haven't figured out a way to do it that doesn't have the client start depending on the timing of input bytes, which I hate to do.
If we want to capture Putty's ESC [ 1 ~ (khome) and turn it into xterm's ESC O H (khome), we basically have to eat ESC [ and then observe the rest of the escape sequence before printing O H. But I'm not comfortable just eating ESC [ and sitting there indefinitely without printing the [ . On the other hand, I hate the idea of a timeout.
On the third hand, maybe the least bad path is a timeout -- but only when the outer terminal requires this kind of translation (so not for TERM=xterm).
josch commentedon Jan 29, 2013
until this is fixed, starting mosh inside gnu screen seems to be a workaround (I want to drop neither urxvt nor mosh)
hexchain commentedon Dec 22, 2013
I had this problem too. Manully exporting TERM=rxvt-unicode-256color on server after connecting makes Home/End keys behave well in applications, but unfortunately not that shell.
Will there be any problem if mosh just passes the client $TERM to server?
Solve mobile-shell#178
Fix issue mobile-shell#178
andersk commentedon Jul 28, 2014
Passing
TERMto the server is not the right approach; see my comment #446 (comment).This needs to be done via translation on the client side in order for the client and server to agree about the state of the terminal at all times. Probably the most clever approach would be to read the client’s terminfo entry and learn the translation automatically from that (like ncurses does).
keithw commentedon Dec 17, 2014
I don't think this issue (about rxvt cursor-key sequences sent from the terminal to the application) is related to colors (sequences sent from the application to the terminal). Your comment is probably better on issue #557 .
awwaiid commentedon Feb 4, 2015
All I know is that when I edit src/frontend/mosh-server.cc and s/xterm-256color/rxvt-unicode-256color/ all my home/end issues go away and I don't notice any further issues :) . I guess I need to get the remote system to understand xterm-256color as the "right" solution.
chandlerc commentedon Dec 16, 2015
Just hit this issue.
I connect with mosh using both xterm and rxvt-unicode and the different escape codes completely hose things. I think that this really needs some solution. I would be happy with either parsing the escape codes or causing the server to be run with the correct TERM...
txtsd commentedon Jan 5, 2016
moshincorrectly sets$TERMasxterm-256colorwhilesshcorrectly sets it asrxvt-unicode-256colorI have my.zshrcset up with escape sequence hackery to get around this, but it shouldn't be necessary at all.EDIT: I thought I did. It doesn't work.
Secretions commentedon Mar 29, 2016
The workaround I'm using for the time being in my .zshrc is checking if TERM is set to xterm*, changing it to rxvt, then doing exec zsh. The exec zsh replaces the current shell with a new instance so the shell itself inherits the TERM variable.
If you try to do something similar, it's absolutely critical that the exec can't get executed on a subsequent run of zsh, or your ability to login via that shell will be completely hosed. Just looking at it causes me anxiety. :)
grawity commentedon Mar 29, 2016
@Secretions: So why use evil hacks like this at all, rather than setting up the needed keybindings directly? For example:
Secretions commentedon Mar 29, 2016
Because, like txtsd, I attempted to setup the keybindings and failed. :)
Looks like the two that are needed are:
bindkey '\e[7~' beginning-of-line
bindkey '\e[8~' end-of-line
Much less insane than what I was doing above. In my first attempt to set the keybindings, I had it in my head to use "^[[1~" and "^[[4~", which was not correct. Thanks.
6 remaining items
hhirsch commentedon Aug 10, 2016
I have the same issue. It is a dealbreaker for me. I am back to using ssh.
josch commentedon Aug 10, 2016
@hhirsch in case it helps: I am using mosh like this:
And my
~/.screenrchas:Which is okay since I normally use tmux for everything. I did not edit any other configuration files.
With this setup I have not yet encountered any issues. I'm using mcabber and irssi inside that tmux session on
myserverwhere I frequently use keys like Home/End and PageUp/PageDown.hhirsch commentedon Aug 10, 2016
@josch Well to me this seems like too much trouble to make a square wheel turn.
ssh does not have bugs like this so I just stick to it. If basic stuff like this is broken who knows what else is. I'll try again in 10 years when this issue is fixed.
tsmithe commentedon Sep 16, 2016
I must also comment that this certainly does not work for me, even using the `screen' trick described above. In particular, I encounter #161. Why does mosh have to emulate a terminal? Why can't it just pass back and forth the byte sequences produced by and for the user's actual terminal?
andersk commentedon Sep 16, 2016
@tsmithe Mosh relies on a deep understanding of the terminal input and display for its latency reduction tricks. (“But I have a fast network and I don’t need those!” Great, go use SSH then. “But I want Mosh’s automatic roaming!” Well, I sympathize—there’s a place in the world for a version of SSH with just the addition of automatic roaming. But Mosh is not that and cannot reasonably be made into that.)
The screen-in-urxvt workaround does fix the Home/End keys as advertised. It does not help with Ctrl-Arrow keys, but I think that is a screen bug: Ctrl-Arrow keys do not work in screen-in-urxvt even when Mosh is not involved.
tsmithe commentedon Sep 16, 2016
Interesting; I did not expect that mosh's features depended on such hidden complexity! Thanks for your reply.
I did respect the order for the workaround commands, but with no luck. I will have to investigate more deeply. Should you have any debugging suggestions, I would be glad to hear them, but I suspect I have not provided sufficient detail for that (simply due to ignorance..).
tsmithe commentedon Sep 17, 2016
EDIT: I may have spoken too soon, but I will return later when I actually get things working fully..
Both fortunately and unfortunately, the best solution I seem to have found for my configuration is to use the urxvt keysym mappings given at http://www.netswarm.net/misc/urxvt-xtermcompat.txt (to simulate an xterm), in conjunction with a local tmux. If I run mosh within that urxvt+xtermcompat+tmux configuration, then I get the expected behaviour remotely: that is, sequences such as Ctrl-Arrow and Home/End work just fine.
Although I can speculate, I am not completely sure why this is -- and why this works whilst other suggestions do not -- but I hope this might be helpful to others.
anarcat commentedon Sep 18, 2016
@tsmithe that does look like a nasty piece of hack. i wonder what the urxvt people think of that one. ;) does it also work with screen?
tsmithe commentedon Sep 18, 2016
@anarcat, you are right, it is a nasty hack..
I have found that, with the following .emacs snippet, the xtermcompat hack is unnecessary if I use the screen workaround described above (again, I use tmux for everything, so that's fine). But without this .emacs snippet, I do not get the correct remote behaviour either with the xtermcompat hack, or with the screen workaround. Note that, in both cases (xtermcompat hack, and screen workaround), I find this snippet to be necessary to get the correct remote behaviour in emacs. I am not sure why emacs (24.5.1) needs it!
I do not know what the 'select' key is. Running 'read' at the remote end gives me
^[[4~, which is just what I get locally, where there is no `select' problem!I will add further mappings as and when I find or need them. In particular, I still do not get the right behaviour (seemingly in any case so far!) if I have a local tmux session, with a nested remote tmux session in mosh.
Fundamentally, it just seems like mosh doesn't interpret urxvt I/O correctly, but it does a better job with a client-side tmux session, which in turn does a reasonable job with urxvt... This means that I have a passably working set-up, and can therefore enjoy the many benefits of mosh. These benefits comfortably outweigh the frustrations of these hacks, for now!
EDIT: The solution (for now..) for the nested remote tmux problem was to turn on the xterm-keys tmux option remotely.
blueyed commentedon Sep 18, 2016
@tsmithe
How is this less hackish? :D
Trollwut commentedon Jan 29, 2019
Little workaound for me was installing
rxvt-unicode(which I'm using on my client too) and then puttingexport TERM=rxvt-unicodeinto the~/.bashrcof the user I'm connecting to.Works for me, even
suinto another account.EDIT: before putting that into your bashrc, you can just run
echo $TERMto see that it says something xterm. Then runningexport TERM=rxvt-unicodemight fix it. If so, you can put it into your bashrc.wilhelmy commentedon Aug 1, 2019
I switched back from tmux to screen for a while (not quite knowing which part of the chain of terminal emulators broke this) because screen apparently translates rxvt keys to xterm keys, while tmux does not. Now I'm back to tmux (because it's just so much nicer) and I would really appreciate if there was a fix for this. Setting
TERM=rxvt-unicode-256colorfor now because it seems like a viable workaround.She110ck commentedon May 5, 2023
If we talking about passing
$TERMvariable (in my case wrong colors issue) simplest solution just run nested bash session:If you use tmux for everything:
posh: escape-to-shell over relay/mux channels — fix mobile-shell#178