当前位置: 首页 > news >正文

Linux shell编程学习笔记27:tputs

除了stty命令,我们还可以使用tput命令来更改终端的参数和功能。

1 tput 命令的功能

tput 命令的主要功能有:移动更改光标、更改文本显示属性(如颜色、下划线、粗体),清除屏幕特定区域等。

2 tput 命令格式

 tput [选项] [参数]

 

3 设置文本颜色属性

3.1 tput setaf / setbf :设置前景色 / 背景色

命令格式:

  •   tput setab n : 设置背景色,set text attributes background color
  •   tput setaf  n : 设置前景色,set text attributes front color


​参数n:

  •   0 – Black,黑色
  •   1 – Red,红色
  •   2 – Green,绿色
  •   3 – Yellow,黄色
  •   4 – Blue,蓝色
  •   5 – Magenta,品红
  •   6 – Cyan,青色
  •   7 – White,白色


例子:设置前背景色为黄色(3),背景色为品红(5)。

csdn @ edu bash ~ $ tput setaf 3 setab 5 
csdn @ edu bash ~ $ tput  setab 5 
csdn @ edu bash ~ $ 

看来不能在一个命令中同时设置前景色和背景色,要分开来用两个命令分别设置。

csdn @ edu bash ~ $ tput setaf 3; tput setab 5 
csdn @ edu bash ~ $ 

3.2 tput rev:反显当前的颜色方案

rev源自reverse。

csdn @ edu bash ~ $ tput setaf 3; tput setab 5 
csdn @ edu bash ~ $ tput rev
csdn @ edu bash ~ $ 


4 设置文本模式属性

命令功能
tput bold加粗字体
tput dim打开高亮模式,turn on half-bright mode
tput smul添加下划线,start mode of underline,
tput rmul 取消下划线,remove mode of underline
tput smso突出模式,start mode of standout
tput rmso反显突出模式,reverse mode of standout
tput sgr0set global attributes return to 0, 取消所有属性

csdn @ edu bash ~ $ tput setaf 3; tput setab 5 
csdn @ edu bash ~ $ tput smso
csdn @ edu bash ~ $ tput rmso
csdn @ edu bash ~ $ tput smul
csdn @ edu bash ~ $ tput bold
csdn @ edu bash ~ $ tput rmul
csdn @ edu bash ~ $ tput dim
csdn @ edu bash ~ $ tput sgr0

csdn @ edu bash ~ $

5 设置光标属性

命令功能
tput clear清屏
tput sc保存当前光标位置,save curosr position
tput rc恢复光标位置,restore cursor postion
tput cup row column将光标移动到指定行row和列column,
tput civis 光标不可见,cursor invisible
tput cnorm光标可见,cursor mormal
tpu init清空格式

我们将执行以下命令序列:

tput clear                   # 清屏
tput sc                      # 保存当前光标位置
tput cup 10 13               # 将光标移动到第10行第13列
echo -n Enter your password: # 提示用户输入密码
tput civis                   # 光标不可见
read p                       # 将用户输入的密码保存到变量p中
tput cnorm                   # 光标可见
tput rc                      # 恢复光标位置
echo your password: $p       # 显示用户输入的密码

csdn @ edu bash ~ $ tput clear;tput sc;tput cup 10 13;echo -n Enter your password:;tput civis; read p; tput cnorm; tput rc; echo your password: $p 

 

6 其它功能

命令功能
tput lines 显示行数
tpus cols显示列数
tput reset  重置终端设置
tput longname显示当前终端类型的长名称
tput hs        具有状态行

csdn @ edu bash ~ $ tput lines
22
csdn @ edu bash ~ $ tput cols
132
csdn @ edu bash ~ $ tput longname
xterm terminal emulator (X Window System)csdn @ edu bash ~ $ 

 

http://www.lryc.cn/news/235069.html

相关文章:

  • 【计算机网络笔记】IPv6简介
  • c语言-数据结构-堆
  • ROS基础—关于参数服务器的操作
  • Sql Server 2017主从配置之:事务日志传送
  • 每日OJ题_算法_双指针_力扣283. 移动零+力扣1089. 复写零
  • WebGl-Blender:建模 / 想象成形 / Blender概念词汇表 / 快捷键
  • 【C++】【Opencv】cv::warpAffine()仿射变换函数详解,实现平移、缩放和旋转等功能
  • WPF实现右键菜单
  • Java智慧工地SaaS管理平台源码:AI/云计算/物联网
  • 【漏洞复现】通达oa 前台sql注入
  • 机器学习笔记 - Ocr识别中的文本检测EAST网络概述
  • 【SQL server】数据库、数据表的创建
  • vue的生命周期分别是什么?
  • Java拼图游戏
  • Vue框架的element组件table文字居中
  • 科技创新 共铸典范 | 江西卫健办邓敏、飞图影像董事长洪诗诗一行到访拓世科技集团,提振公共卫生事业发展
  • Linux安装OpenCV并配置VSCode环境
  • Django(ORM事务操作|ORM常见字段类型|ORM常见字段参数|关系字段|Meta元信息)
  • 【mujoco】Ubuntu20.04配置mujoco210
  • 【洛谷 P3853】[TJOI2007] 路标设置 题解(二分答案+循环)
  • 蓝桥杯 vector
  • ai绘画部署教程
  • 策略模式的应用——应对频繁的需求变更
  • qt-C++笔记之treeWidget初次使用
  • SQL零基础入门教程,贼拉详细!贼拉简单! 速通数据库期末考!(八)
  • C语言编程陷阱(八)
  • 客户端性能优化实践
  • mysql使用--表达式和函数
  • <蓝桥杯软件赛>零基础备赛20周--第6周--数组和队列
  • 软件开发、网络空间安全、人工智能三个方向的就业和前景怎么样?哪个方向更值得学习?