5

I have this strange issue, that I cannot find the source of, nor a solution to solve.

"Sometimes" my zsh gets messed up and start display end of lines in a funny way:

Screenshot

As you can see, the newlines are ignored and I get a funny % at the end of the line.

Do you know what may cause this and how to solve it?

Note: I'm running OS X, a zsh inside Iterm2 and Tmux.

  • 1
    Does reset help? – muru May 11 '16 at 14:08
  • Yes, it seems to restart the session. Is it the case, or is only the display refreshed? (nice to see you here btw) – nobe4 May 11 '16 at 14:10
  • 1
    It doesn't restart the session; it just resets the terminal settings. Probably related to unix.stackexchange.com/q/49886/70524 (you too!) – muru May 11 '16 at 14:14
3

The screenshot shows what is called "staircasing", where the newline sent from the computer to the terminal is not automatically translated to a carriage-return / line-feed by the terminal driver.

You would see this after running a program that modifies the terminal modes temporarily, but does not succeed in restoring the original modes. You would never see this as a result of cat'ing a binary file to the screen.

You can produce this behavior on some shells (others such as tcsh reset the terminal modes after each command). Here is an example using dash:

$ stty -a
speed 38400 baud; rows 40; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
$ stty -onlcr
$ stty -a
         speed 38400 baud; rows 40; columns 80; line = 0;
                                                         intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>;
                                              eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
                                            werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
                   -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
                                                                            -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
                                                                          -iuclc -ixany -imaxbel -iutf8
                       opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
                       isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
                  echoctl echoke
                                $ 

The reset command, as suggested, will reset the terminal modes, but also resets features on the terminal itself. You could also use

stty sane

or more specifically

stty onlcr

but reset involves the least typing.

Further reading:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.