fix non-interactive mode: skip TUI and use simple output

The fancy cursor-positioning TUI (get_line, print_block, tput) fails in
non-interactive contexts like Vagrant provisioning where there's no real
terminal. Now when --non-interactive is passed, uses simple echo-based
output instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Anton Volnuhin 2026-03-03 01:42:45 +03:00
parent 5104a5313b
commit 3e53d99ad2

View File

@ -81,6 +81,7 @@ fi
cd cd
if [ "$NON_INTERACTIVE" -eq 0 ]; then
echo -e " echo -e "
$Green""############################################################################### $Green""###############################################################################
@ -94,62 +95,78 @@ $Green""########################################################################
" "
read read
fi
#Setup #Setup
TERM_WIDTH_BASE=$(stty size 2>/dev/null | awk '{print $2}')
TERM_WIDTH_BASE=${TERM_WIDTH_BASE:-80}
PADDING=$(printf "%${PAD_LEN}s") # 4 spaces of padding
TERM_WIDTH=$(($TERM_WIDTH_BASE - $PAD_LEN))
USER=$(whoami) USER=$(whoami)
STEP=1 STEP=1
get_line () if [ "$NON_INTERACTIVE" -eq 1 ]; then
{ # Simple output for non-interactive mode (Vagrant, CI, etc.)
IFS='[;' read -p $'\e[6n' -d R -a pos -rs || echo "failed with error: $? ; ${pos[*]}" new_line () {
echo ${pos[1]} echo -e "\n--> $Blue$1$NC"
}
print_block ()
{
local ln=$(get_line)
if [[ "$ln" -lt "$(($LINES - $STEPS))" ]];then
tput cup $(($LINES - $STEPS - 2)) 0
else
ln=$(($LINES - $STEPS - 1))
fi
echo "..........................................................."
for i in $(seq 1 $STEPS)
do
echo -n " >"
tput el
echo
done
tput cup $(($ln - 3)) 0
}
new_line () {
# move cursor to current step's line
local ln=$(get_line)
tput csr 0 $LINES
tput cup $(($LINES - $STEPS - 2 + $STEP)) 0
echo -e "==> "$Green$1$NC
STEP=$(($STEP + 1)) STEP=$(($STEP + 1))
}
tput csr 0 $(($LINES - $STEPS - 3)) pad() {
tput cup $(($ln - 1)) 0 cat
echo -e "\n--> "$Blue$1$NC }
tput el
}
pad() { print_block () { :; }
while IFS= read -r line; do else
echo -e $Gray$line$NC | fold -s -w $TERM_WIDTH | sed "s/^/$PADDING/" TERM_WIDTH_BASE=$(stty size 2>/dev/null | awk '{print $2}')
done TERM_WIDTH_BASE=${TERM_WIDTH_BASE:-80}
} PADDING=$(printf "%${PAD_LEN}s") # 4 spaces of padding
TERM_WIDTH=$(($TERM_WIDTH_BASE - $PAD_LEN))
get_line ()
{
IFS='[;' read -p $'\e[6n' -d R -a pos -rs || echo "failed with error: $? ; ${pos[*]}"
echo ${pos[1]}
}
print_block ()
{
local ln=$(get_line)
if [[ "$ln" -lt "$(($LINES - $STEPS))" ]];then
tput cup $(($LINES - $STEPS - 2)) 0
else
ln=$(($LINES - $STEPS - 1))
fi
echo "..........................................................."
for i in $(seq 1 $STEPS)
do
echo -n " >"
tput el
echo
done
tput cup $(($ln - 3)) 0
}
new_line () {
# move cursor to current step's line
local ln=$(get_line)
tput csr 0 $LINES
tput cup $(($LINES - $STEPS - 2 + $STEP)) 0
echo -e "==> "$Green$1$NC
STEP=$(($STEP + 1))
tput csr 0 $(($LINES - $STEPS - 3))
tput cup $(($ln - 1)) 0
echo -e "\n--> "$Blue$1$NC
tput el
}
pad() {
while IFS= read -r line; do
echo -e $Gray$line$NC | fold -s -w $TERM_WIDTH | sed "s/^/$PADDING/"
done
}
fi
{{ if eq .chezmoi.os "linux" -}} {{ if eq .chezmoi.os "linux" -}}
@ -160,9 +177,10 @@ pad() {
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}
LINES=$(tput lines) if [ "$NON_INTERACTIVE" -eq 0 ]; then
LINES=$(tput lines)
print_block print_block
fi
new_line "Update caches and upgrade packages" new_line "Update caches and upgrade packages"
{{ if eq .chezmoi.os "freebsd" -}} {{ if eq .chezmoi.os "freebsd" -}}
@ -434,7 +452,9 @@ then
$SUDO chsh -s $(command -v fish) $USER $SUDO chsh -s $(command -v fish) $USER
fi fi
tput csr 0 $LINES if [ "$NON_INTERACTIVE" -eq 0 ]; then
tput cup $LINES 0 tput csr 0 $LINES
tput cup $LINES 0
fi
echo echo