我正在使用 while 循环来执行生成一堆文件的 ffmpeg 操作,我希望屏幕底部有一个指示器,指示我正在处理的文件,它位于屏幕底部,同时ffmpeg 正在提供输出。有点类似于 apt 包管理器中的方式,有一个进度条始终位于底部,同时它在其上方提供输出信息。我不需要进度条,只需要一串包含文件编号的文本,它始终位于底部。
我的代码的一个非常简化的版本:
# Initialize file number
file_number=1
while IFS=, read -r starttime name endtime; do
# ffmpeg command
ffmpeg -ss $starttime_seconds -i "$1" -t $duration -codec libopus "$safename" < /dev/null
# Display progress, this is what I want at the bottom of the screen
echo -en "\r--- FILE $file_number ---"
file_number=$((file_number+1))
done < "$2"
最佳答案
使用tput
。在你的代码中替换
echo -en "\r--- FILE $file_number ---"
与
print_status
并将其放在您的代码之前:
LINES=$(tput lines)
set_window ()
{
# Create a virtual window that is two lines smaller at the bottom.
tput csr 0 $(($LINES-2))
}
print_status ()
{
# Move cursor to last line in your screen
tput cup $LINES 0;
echo -n "--- FILE $file_number ---"
# Move cursor to home position, back in virtual window
tput cup 0 0
}
set_window
参见:man tput
和 man 5 terminfo
关于bash - 如何在终端窗口的底部显示文本,并让它留在 Bash 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63661567/