60

The problem I have happens after a ssh connection has been ended by closing my MacBook (putting it in stand-by mode). I come back and it's written broken pipe.

When I click on the terminal window, a succession of characters appear. If I click several times, then the combination of these characters will appear the same number of times.

By moving my cursor, I can change the combination of letters...
Here, between every line, I moved my cursor somewhere else on my Desktop.

The strange behaviour in image

The content of my ~/.bash_profile is:

# Tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad

# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'

export TERM="xterm-color"
PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '


# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# added by Anaconda3 5.2.0 installer
export PATH="/anaconda3/bin:$PATH"

Versions:

  • macOS High Sierra version 10.13.5
vvvvv
  • 771
  • 1
  • 5
  • 11

5 Answers5

109

You have somehow activated the terminal's mouse tracking mode. This is usually used by terminal applications which accept mouse input (like vim), which can interpret these character sequences as mouse events. The shell does not support mouse input, so it displays these sequences directly.

You can turn off mouse tracking mode by running the reset command in the terminal.

  • It works. but I don't understand why it works? `reset` is a command to the shell, while mouse tracking mode is for the terminal app. I guess that `reset` does not disable terminal app's mouse tracking, so it preventing the shell accepting mouse actions? – bruin Sep 02 '22 at 01:10
10

I just had this issue and going to view > Allow (or disallow) mouse reporting will solve it.

enter image description here

Mark Clifford
  • 101
  • 1
  • 2
3

When the Terminal (well, one of its ttys, anyway) is not accepting keyboard input in a reliable manner and needs a hard reset, either:

A.) hold down the ⌥ and ⌘ keys, and tap the R key [option-command-r]; or:
B.) Invoke the same action under the "Shell" dropdown menu of Terminal.app:


Terminal Hard Reset

Doc G.
  • 2,338
  • 13
  • 15
3

I realized if you use Tmux and a session disconnects this happens if you have enabled the mouse on function within Tmux.

I discovered this because I had two terminals open on my server using the same terminal program (Termius on mac). One terminal I was using Tmux and the other one I was not. Tmux had mouse option set to on so I could resize panes, click between windows, etc within Tmux

ONLY the Tmux terminal exhibited this behavior when I reconnected both terminals after the computer had gone to sleep and I reconnected. So upon reconnect the Tmux terminal (even though the reconnected session was not yet attached back to tmux) held onto the mouse aware setting and would insert characters on every click.

There are several fixes. The easiest is to just use the RESET command in the terminal. You can also quit your terminal program completely and restart it then login.

I am looking into setting a bash login to automatically send clear command to the terminal as soon as I log in.

Marc
  • 31
  • 1
1

I faced this issue on Windows Terminal. The command line always wrote different weird characters. The solution for me was to open a vim page and close.

vim

and quit vim with

:q 
Sahin
  • 111
  • 1
  • 1
    Nice! I discovered that the command `vim +q` will do it all at once. (So no explicit quitting within `vim` is necessary.) – J-L Mar 08 '22 at 20:04