Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions dist/libexec/common-shared
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
# * Credits: This script is based on the script generated by sbt-pack.
# *--------------------------------------------------------------------------*/

# save terminal settings
saved_stty=$(stty -g 2>/dev/null)
# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
if [ -e /usr/bin/tty -a "`tty`" != "not a tty" -a ! -p /dev/stdin ]; then
Copy link
Member

@hamzaremmal hamzaremmal Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and played a bit with the locale and it seems that tty will always output 'not a tty' regardless of the current locale. Which means that we can rely on that output being in the same language.

% date Sun Mar 9 14:58:45 CET 2025 % tty < /dev/null not a tty % export LANG=fr_FR.UTF-8 % date Dim 9 mar 2025 14:59:00 CET % tty < /dev/null not a tty
isterminal=1
# save terminal settings
saved_stty=$(stty -g 2>/dev/null)
# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you clear the cached stty but you don't clear the isterminal variable. The code below will try to recover the stty if isterminal is set to 1. Locally, recovering the stty with these parameters might be problematic:

% stty speed 9600 baud; lflags: echoe echoke echoctl pendin iflags: iutf8 oflags: -oxtabs cflags: cs8 -parenb % stty "" stty: illegal option -- usage: stty [-a | -e | -g] [-f file] [arguments]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. Clearing isterminal when stty is cleared seems correct.

fi
else
isterminal=0
fi

# restore stty settings (echo in particular)
function restoreSttySettings() {
stty $saved_stty
[ $isterminal -eq 1 ] && stty $saved_stty
saved_stty=""
}

Expand Down Expand Up @@ -61,7 +66,7 @@ if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then
CYGPATHCMD=`which cygpath 2>/dev/null`
case "$TERM" in
rxvt* | xterm* | cygwin*)
stty -icanon min 1 -echo
[ $isterminal -eq 1 ] && stty -icanon min 1 -echo
JAVA_OPTS="$JAVA_OPTS -Djline.terminal=unix"
;;
esac
Expand Down
Loading