您好,登錄后才能下訂單哦!
Shell中怎么實(shí)現(xiàn)飛行文字效果,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
#!/bin/bash [ -z $1 ] && echo "Input is invalid! " && exit 1 txt=($(cat $1|sed 's/ \+/_/g')) lines=${#txt[@]} max_show=10 #最多顯示行數(shù)(超過(guò)總行數(shù)則設(shè)為總行數(shù)) [ ${max_show} -gt ${lines} ] && max_show=${lines} hlt_line=3 #高亮顯示位置(不超過(guò)總行1/2,設(shè)為3實(shí)際是第4行) [ ${hlt_line} -gt $(( lines / 2 )) ] && hlt_line=$(( lines / 2 )) sTTY=$(stty -g) #保存終端設(shè)置 clear echo -ne "\033[?25l" #隱藏光標(biāo) spaces() { local i j n i=0; n=0 for (( j=0; j <= ${lines}; j++ ));do [ $i -lt ${#txt[$j]} ] && (( i = ${#txt[$j]} )) && (( n = $j )) done echo ${txt[$n]}|sed 's/./ /g' } space_line=$(spaces) #傳遞的參數(shù)是欲顯示行的序數(shù):show 1 表示第一行高亮顯示 show() { local i j text crt_line j=$1 for (( i=0; i < max_show; i++ ));do crt_line=$(( j + i - hlt_line )) if [ $i -eq ${hlt_line} ] && [ ${crt_line} -ge 0 ] && [ ${crt_line} -le ${lines} ];then text="\033[;32m"${txt[${crt_line}]}"\033[0m" elif [ ${crt_line} -lt 0 ] || [ ${crt_line} -gt ${lines} ];then text=${space_line} else text=${txt[${crt_line}]} fi echo -ne "\033[$((i+3));0H${space_line}" echo -ne "\033[$((i+3));6H${text}" done } #測(cè)試 for (( j = 0; j < lines + hlt_line +1 ; j++ ));do show $j sleep 1 done
恢復(fù)默認(rèn)設(shè)置方法:
echo "" stty ${sTTY} #恢復(fù)終端設(shè)置 echo -e "\033[?25h\033[0;0H" #恢復(fù)光標(biāo)
關(guān)于Shell中怎么實(shí)現(xiàn)飛行文字效果問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。