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,16 +95,31 @@ $Green""########################################################################
" "
read read
fi
#Setup #Setup
USER=$(whoami)
STEP=1
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))
}
pad() {
cat
}
print_block () { :; }
else
TERM_WIDTH_BASE=$(stty size 2>/dev/null | awk '{print $2}') TERM_WIDTH_BASE=$(stty size 2>/dev/null | awk '{print $2}')
TERM_WIDTH_BASE=${TERM_WIDTH_BASE:-80} TERM_WIDTH_BASE=${TERM_WIDTH_BASE:-80}
PADDING=$(printf "%${PAD_LEN}s") # 4 spaces of padding PADDING=$(printf "%${PAD_LEN}s") # 4 spaces of padding
TERM_WIDTH=$(($TERM_WIDTH_BASE - $PAD_LEN)) TERM_WIDTH=$(($TERM_WIDTH_BASE - $PAD_LEN))
USER=$(whoami)
STEP=1
get_line () get_line ()
{ {
@ -150,6 +166,7 @@ pad() {
echo -e $Gray$line$NC | fold -s -w $TERM_WIDTH | sed "s/^/$PADDING/" echo -e $Gray$line$NC | fold -s -w $TERM_WIDTH | sed "s/^/$PADDING/"
done done
} }
fi
{{ if eq .chezmoi.os "linux" -}} {{ if eq .chezmoi.os "linux" -}}
@ -160,9 +177,10 @@ pad() {
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}
if [ "$NON_INTERACTIVE" -eq 0 ]; then
LINES=$(tput lines) 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
if [ "$NON_INTERACTIVE" -eq 0 ]; then
tput csr 0 $LINES tput csr 0 $LINES
tput cup $LINES 0 tput cup $LINES 0
fi
echo echo