Samuel Jackson
Samuel Jackson

Reputation: 113

Console output becomes misaligned

Description

Once in a while I'll be working on things and suddenly my console's alignment gets completely messed up. I think it's usually after a command fails or crashes (though I haven't been able to pin down a specific command that causes it). It looks looks like \r is no longer being output or read correctly or the terminal has some non-interactive mode flag set.

Environment

I'm running ZSH with OMZ inside of tmux inside of iterm2.

Photo

enter image description here

Upvotes: -1

Views: 84

Answers (1)

rcwnd_cz
rcwnd_cz

Reputation: 1036

This misalignment can be caused by various reasons, including a command messing with the terminal settings and being killed before it can restore them on exit, or by a command outputting unexpected control sequences.

You can easily reproduce these conditions by:

  • Resizing the terminal window during cat output.
  • Using cat or similar commands like head or tail on binary files.
  • Force-killing applications that modify terminal settings, such as screen or less.

Fortunately, there are programs that can reset terminal settings back to normal:

  • For very mild conditions, you can always use clear or, in most shells, press Ctrl-L. This will clear the screen but keep the scrollback buffer.
  • You can force the recalculation of terminal dimensions by using resize command.
  • Using stty sane will reset most of the crucial terminal settings while keeping the screen content and scrollback buffer intact.
  • For more severe conditions, you can use reset, which is usually an alias or link to tput reset. This will restore the terminal to a sane mode, resetting most of the crucial capabilities, including clearing the scrollback buffer.
  • In rare cases where none of the above works, the issue might be with the shell itself. In such cases, running exec $SHELL -l after resetting the terminal can help.

Upvotes: 1

Related Questions