I am debugging a show glitch that happens within the operation of Basta (Bash Standing Line) on macOS.
Every time the interrupt arrives to refresh the clock show, the cursor column place doesn’t restore, solely the row place. I.e. the cursor jumps to the leftmost column. That occurs each 15 seconds, which is the replace interval.
When the person continues typing, every little thing is okay; the cursor jumps again into the Bash command line on the right spot.
Basta makes use of the ESC 7
and ESC 8
sequences to avoid wasting and restore the cursor place across the replace. This works on quite a few terminals, Gnome Terminal, PuTTY, Xterm, and others.
Sadly, the issue does not reproduce in a small check case resembling this:
esc=$(printf " 33")
printf "cursor must be right here: ${esc}7 <---r${esc}8"
learn
On this check case, we print the <---
arrow after the cursor place after which navigate to the beginning of the road with a carriage return. Lo and behold, the cursor is restored to the anticipated place simply after the right here:
and the scripts anticipate return to be pressed:
Cursor must be right here: â–ˆ<---
So that works high-quality. Is there recognized some bug in Terminal round this, and in that case, the place is it documented, and what are the situations underneath which it occurs and repro steps?
New information: Utilizing the script
utility, I captured what will the terminal. If I simply let it sit there, then what occurs each 15 seconds is that this:
...^[8^[[?2004l^M^[[?2004h^[7...
The ^[8
is the epilogue of the earlier replace, issued by the alarm handler in Basta: that is the very last thing it prints, to revive the cursor place. The ^[7
towards the tip is the beginning of the subsequent replace, to avoid wasting the cursor place. In between, we count on nothing. But, Bash does one thing: ^[[?2004l^M^[[?2004h
. These two escape sequences are personal ANSI extensions. ?2004l
is “flip off bracketed paste mode”, and ?2004h
is “flip off bracketed paste mode”. In between is the ^M
carriage return that places the cursor to the beginning of the road. Bash is aware of about this as a result of when the person begins typing, some right cursor motion instructions are issued to maneuver to the proper spot.
Backside line, Bash is doing this. However why? Why is Bash twiddling with bracketed paste enabling and disabling terminal escape sequences, simply because it acquired a sign?
The Bash executable is the one from Homebrew, $BASH_VERSION
is 5.2.37(1)-release
.
Extra new information: I’ve confirmed that when Bash has an ALRM
entice
set and receives that sign, it prints rubbish to the terminal. When no entice
is ready, nothing occurs.
The only entice we are able to set which reproduces it’s to attach the ALRM
sign to the shell null command, which consists of a colon (:
):
entice : ALRM
Then if I begin a background course of which repeatedly sends a SIGALRM
to Bash, whereas Bash sits on the command immediate, Bash repeatedly prints these sequences:
^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M^[[?2004h^[[?2004l^M
If no entice
is ready for that sign, nothing is printed. However in fact, the entice is simply the :
command which does nothing; the printing is coming from inside Bash someplace.
It doubtless has nothing to do with MacOS, besides that I’ve not seen this earlier than, and I am seeing it on MacOS utilizing the Homebrew construct of Bash.