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
if [ "$NON_INTERACTIVE" -eq 0 ]; then
echo -e "
$Green""###############################################################################
@ -94,62 +95,78 @@ $Green""########################################################################
"
read
fi
#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)
STEP=1
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
if [ "$NON_INTERACTIVE" -eq 1 ]; then
# Simple output for non-interactive mode (Vagrant, CI, etc.)
new_line () {
echo -e "\n--> $Blue$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() {
cat
}
pad() {
while IFS= read -r line; do
echo -e $Gray$line$NC | fold -s -w $TERM_WIDTH | sed "s/^/$PADDING/"
done
}
print_block () { :; }
else
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))
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" -}}
@ -160,9 +177,10 @@ pad() {
{{ end -}}
{{ end -}}
LINES=$(tput lines)
print_block
if [ "$NON_INTERACTIVE" -eq 0 ]; then
LINES=$(tput lines)
print_block
fi
new_line "Update caches and upgrade packages"
{{ if eq .chezmoi.os "freebsd" -}}
@ -434,7 +452,9 @@ then
$SUDO chsh -s $(command -v fish) $USER
fi
tput csr 0 $LINES
tput cup $LINES 0
if [ "$NON_INTERACTIVE" -eq 0 ]; then
tput csr 0 $LINES
tput cup $LINES 0
fi
echo