转载自: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. Java 对象引用以及对象赋值

    一.Vehicle veh1 = new Vehicle(); 通常这条语句执行的动作被称为创建一个对象,其实他包含了四个动作. 1.new Vehicle  :表示在堆空间内创建了一个Vehicle ...

  2. android sqlite,大数据处理、同时读写

    1. 批量写入,采用事物方式,先缓存数据,再批量写入数据,极大提高了速度 288条,直接inset  into  耗时7秒 8640条,     批量写入  耗时5-7秒 try { this.myD ...

  3. [转]_int64、long long 的区别

    大学生程序代写 C++的64位整数[原]by 赤兔 http://baike.baidu.com/view/1235293.htm 在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常 ...

  4. 基于DirectShow和FFmpeg的USB摄像头监控软件-转

    第一个版本 ### 软件版本及实现功能 0.0.1 1. USB摄像头枚举和设备信息获取2. 实时视频观看3. 24小时不间断录像,录像文件支持暴风影音播放 ### 软件说明: 软件基于 Direct ...

  5. POJ1904 King's Quest

    King's Quest Language:Default King's Quest Time Limit: 15000MS Memory Limit: 65536K Total Submission ...

  6. jQuery DataTables 使用手册(精简版)

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/5182940.html 前排提醒,这个插件能不用就不用,那么多好的插件等着你,为什么要用它呢?就算用easyui的 ...

  7. POJ3784:Running Median

    浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=3784 用一个"对顶堆& ...

  8. 【转】Unity3D如何制作落叶效果

    原文地址:http://hi.baidu.com/cupgenie/item/c23861df692f59e3b3f777a8 创建一个粒子系统 GameObject>Create other& ...

  9. 问题7:如何实现用户的历史记录功能(最多n条)

    实例:制作猜字游戏,添加历史记录功能,显示用户最近猜过的数字 解决方案:使用容量为n的队列存储历史记录 使用标准库colections中的deque,一个双端循环队列 程序退出前,可以使用pickle ...

  10. 【转】 Pro Android学习笔记(五八):Preferences(2):CheckBoxPreference

    目录(?)[-] CheckBox Preference xml文件 设备的存贮文件 复合preference 在ListPreference的例子中显示的是单选,如果是多选,可采用CheckBoxP ...