转载自:https://blog.csdn.net/fdipzone/article/details/9993961

什么是 tput?
tput 命令将通过 terminfo 数据库对您的终端会话进行初始化和操作。通过使用 tput,您可以更改几项终端功能,如移动或更改光标、更改文本属性,以及清除终端屏幕的特定区域。

什么是 terminfo 数据库?
UNIX 系统上的 terminfo 数据库用于定义终端和打印机的属性及功能,包括各设备(例如,终端和打印机)的行数和列数以及要发送至该设备的文本的属性。UNIX 中的几个常用程序都依赖 terminfo 数据库提供这些属性以及许多其他内容,其中包括 vi 和 emacs 编辑器以及 curses 和 man 程序。

命令行使用说明:

1.文本属性

tput Color Capabilities:

tput setab [0-7] – Set a background color using ANSI escape
tput setb [0-7] – Set a background color
tput setaf [0-7] – Set a foreground color using ANSI escape
tput setf [0-7] – Set a foreground color

Color Code for tput:

0 – Black
1 – Red
2 – Green
3 – Yellow
4 – Blue
5 – Magenta
6 – Cyan
7 – White

tput Text Mode Capabilities:

tput bold – Set bold mode
tput dim – turn on half-bright mode
tput smul – begin underline mode
tput rmul – exit underline mode
tput rev – Turn on reverse mode
tput smso – Enter standout mode (bold on rxvt)
tput rmso – Exit standout mode
tput sgr0 – Turn off all attributes
例子:使输出的字符串有颜色,底色,加粗

#!/bin/bash

printf $(tput setaf 2; tput bold)'color show\n\n'$(tput sgr0)

for((i=0; i<=7; i++)); do
echo $(tput setaf $i)"show me the money"$(tput sgr0)
done printf '\n'$(tput setaf 2; tput setab 0; tput bold)'background color show'$(tput sgr0)'\n\n' for((i=0,j=7; i<=7; i++,j--)); do
echo $(tput setaf $i; tput setab $j; tput bold)"show me the money"$(tput sgr0)
done exit 0

  

输出格式控制函数:

#!/bin/bash

# $1 str print string
# $2 color 0-7 设置颜色
# $3 bgcolor 0-7 设置背景颜色
# $4 bold 0-1 设置粗体
# $5 underline 0-1 设置下划线 function format_output(){
str=$1
color=$2
bgcolor=$3
bold=$4
underline=$5
normal=$(tput sgr0) case "$color" in
0|1|2|3|4|5|6|7)
setcolor=$(tput setaf $color;) ;;
*)
setcolor="" ;;
esac case "$bgcolor" in
0|1|2|3|4|5|6|7)
setbgcolor=$(tput setab $bgcolor;) ;;
*)
setbgcolor="" ;;
esac if [ "$bold" = "1" ]; then
setbold=$(tput bold;)
else
setbold=""
fi if [ "$underline" = "1" ]; then
setunderline=$(tput smul;)
else
setunderline=""
fi printf "$setcolor$setbgcolor$setbold$setunderline$str$normal\n"
} format_output "Yesterday Once More" 2 5 1 1 exit 0

  

2.光标属性
#!/bin/bash

tput clear # 清屏

tput sc # 保存当前光标位置

tput cup 10 13 # 将光标移动到 row col

tput civis # 光标不可见

tput cnorm # 光标可见

tput rc # 显示输出

exit 0
例子:

#!/bin/bash
# clear the screen
tput clear
# Move cursor to screen location X,Y (top left is 0,0)
tput cup 3 15
# Set a foreground colour using ANSI escape
tput setaf 3
echo "XYX Corp LTD."
tput sgr0
tput cup 5 17
# Set reverse video mode
tput rev
echo "M A I N - M E N U"
tput sgr0
tput cup 7 15
echo "1. User Management"
tput cup 8 15
echo "2. Service Management"
tput cup 9 15
echo "3. Process Management"
tput cup 10 15
echo "4. Backup"
# Set bold mode
tput bold
tput cup 12 15
read -p "Enter your choice [1-4] " choice
tput clear
tput sgr0
tput rc exit 0

  

tput 命令行使用说明的更多相关文章

  1. Kettle命令行使用说明

    Kettle命令行使用说明 1.Pan——转换执行器 用来执行转换.参数与Kitchen类似,如下. 1- -version显示版本信息 2- -file=filename运行xml文件 3- -pa ...

  2. adb shell screenrecord命令行使用说明

    一.查看帮助命令,参数 --help D:\>adb shell screenrecord --help Usage: screenrecord [options] <filename&g ...

  3. (转载)RTorrent 命令行使用说明

    转自:http://blog.chinaunix.net/uid-22457844-id-2973262.html 参考:http://forum.ubuntu.org.cn/viewtopic.ph ...

  4. [译文]casperjs使用说明-使用命令行

    使用命令行 Casperjs使用内置的phantomjs命令行解析器,在cli模块里,它传递参数位置的命名选项 但是不要担心不能熟练操控CLI模块的API,一个casper实例已经包含了cli属性,允 ...

  5. 在非SQL客户端使用命令行方式定期连接SQL Server 服务器并模拟用户查询操作,同时输出信息内容

    一个很长的标题,实现的功能就是尽量使用非人力的方式模拟人去做一件事情,为了便于记录,将他们输出成文件方便查阅. 图形界面方式,使用微软自己的ConnMaker.exe,或者Microsoft 数据连接 ...

  6. Git命令行(转用于学习和记录)

    Git命令行介绍和使用说明(持续更新) 参见:<Git 中文简体教程> 一. 命令“git”或者“git help”查询常用命令 [add]: “git add”——不但是用来添加不在版本 ...

  7. 7Z命令行详解

    7z.exe在CMD窗口的使用说明如下: 7-Zip (A) 4.57 Copyright (c) 1999-2007 Igor Pavlov 2007-12-06 Usage: 7za <co ...

  8. 【转】linux ar 命令的使用说明那个和例子

    from: http://blog.csdn.net/xljiulong/article/details/7082960 linux ar 命令的使用说明那个和例子 标签: linuxmakefile ...

  9. PHP下的命令行执行 php -S localhost -t public

    PHP 的命令行模式     以下是 PHP 二进制文件(即 php.exe 程序)提供的命令行模式的选项参数,您随时可以通过 PHP -h 命令来查询这些参数. Usage: php [option ...

随机推荐

  1. hdu-5637 Transform(位运算+bfs)

    题目链接: Transform Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Other ...

  2. Python解决中文字符的问题

    from __future__ import unicode_literals print(type("test")) #<type 'unicode'> Chinat ...

  3. 006-完全关闭win任务栏鼠标悬停预览

    经过测试, 网上大部分的修改注册表等方法一律没有效果 最终找到一款轻量级软件完美解决问题 下载地址

  4. NYOJ-小猴子下落

    描述 有一颗二叉树,最大深度为D,且所有叶子的深度都相同.所有结点从左到右从上到下的编号为1,2,3,·····,2的D次方减1.在结点1处放一个小猴子,它会往下跑.每个内结点上都有一个开关,初始全部 ...

  5. GCC生成动态库

    main.c #include <stdio.h> void hello(void); int main(int argc, char ** argv) { printf("Th ...

  6. dcos的问题汇总

    . group 'docker' does not exist 需要手工创建docker组,这一步本来应该是在安装docker的时候来完成的,但是采用yum install的方式不行,需要添加一个do ...

  7. Poj_1004_FinancialManagement

    一.Description Larry graduated this year and finally has a job. He's making a lot of money, but someh ...

  8. 问题:C#调webservice超时;结果:C#调用webservice服务超时

    C#调用WebService服务时,报错,The operation has timed out,意思是“操作超时”. 方法/步骤 首先修改服务端配置 WebService服务所在站点为服务端,它提供 ...

  9. Mybaits整合Spring自动扫描 接口,Mybaits配置文件.xml文件和Dao实体类

    1.转自:https://blog.csdn.net/u013802160/article/details/51815077 <?xml version="1.0" enco ...

  10. Gpon与Epon的区别

    一.GPON Gpon(Gigabit-Capable pon)技术起源于ATMPON技术标准,现已形成基于ITU-TG.984.X标准的最新一代宽带无源光综合接入标准. 1.GPON技术特点: 1. ...