Implementing the flying text effect in shell _linux shell

Source: Internet
Author: User

You must have seen the effect of flying words on a Web page, but how do you implement the Echo string in a Linux system, especially in Bash command line mode, with flying effects?
This effect is not practical, but occasionally to amuse themselves or show off a good way, oh, the following to a section of shell script code to explain how to achieve ...

#!/bin/bash [Z $] && echo "Input is invalid!" && exit 1 txt= ($ (Cat $1|sed ' s/\+/_/g ') lines=${ #txt [@]} max_show=10 #最多显示行数 (more than the total number of rows) [${max_show}-gt ${lines}] && Max_show=${lines} hlt_line=3 #高亮显示 Location (no more than row 1/2, set to 3 is actually line 4th) [${hlt_line}-GT $ ((LINES/2))] && hlt_line=$ ((LINES/2)) stty=$ (stty-g) #保存终端设 Place clear Echo-ne "\033[?25l" #隐藏光标 spaces () {local i J n i=0; n=0 for ((j=0; j <= ${lines}; j +));d o [$i- Lt ${#txt [$j]}] && ((i = ${#txt [$j]})) && ((n = $j)) done echo ${txt[$n]}|sed ' s/.//g '} _line=$ (spaces) #传递的参数是欲显示行的序数: Show 1 shows the first line highlighting display () {Local I J-text Crt_line j=$1 for (i=0; i < max_show; i++);d o 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${tex T} ' done} ' #测试 for ((j = 0; J < lines + Hlt_line +1; j +));d o show $j sleep 1 done

To restore the default settings method:

echo ""

stty ${stty} #恢复终端设置

echo-e "\033[?25h\033[0;0h" #恢复光标

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.