tput用法详解-渐入佳境

--作者:飞翔的小胖猪

--创建时间:2021年2月28日

tput 命令将通过 terminfo 数据库对终端会话进行初始化和操作。

主要功能为:移动更改光标、更改文本属性颜色、清除屏幕特定区域、

可以更改终端功能,如移动或更改光标、更改文本属性,以及清除终端屏幕的特定区域。在shell编程的时候可以用来设置颜色。

命令格式:

  tput [option] [parameter]

4.1 tput设置

4.1.1 文本属性颜色

格式:
  tput setab [0-7] – 设置背景色。
  tput setaf [0-7] – 设置前景色。
​参数:
  0 – Black,黑色
  1 – Red,红色
  2 – Green,绿色
  3 – Yellow,黄色
  4 – Blue,蓝色
  5 – Magenta,品红
  6 – Cyan,青色
  7 – White,白色

例子:

设置背景色为黄色。

[root@135 ~]# tput setab 3

设置前景色为黄色

[root@135 ~]# tput setaf 3

4.1.2 文本属性颜色

​格式:
  tput 参数   

参数: 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,突出模式,所有输出字符都突出显示。 tput rmso – Exit standout mode,退出突出显示。 tput sgr0 – Turn off all attributes,取消所有属性。

例子:

设置字符加粗

[root@135 ~]# tput bold

设置取消下划线

#设置显示下划线
[root@135 ~]# tput smul

#取消下划线
[root@135 ~]# tput rmu

设置突出显示字符

#突出模式,所有输出字符都突出显示
[root@135 ~]# tput rev

#突出模式,所有输出字符都突出显示
[root@135 ~]# tput smso

#取消突出模式
[root@135 ~]# tput rmso

4.1.3 光标属性

tput clear # 清屏
tput sc # 保存当前光标位置
tput cup 10 13 # 将光标移动到 row col
tput civis # 光标不可见
tput cnorm # 光标可见
tput rc # 显示输出
tpu init  清空格式
posted @ 2021-02-28 18:23  飞翔的小胖猪  阅读(1564)  评论(0编辑  收藏  举报