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.hqwc.cn/news/192960.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

DPAFNet:一种用于多模式脑肿瘤分割的残差双路径注意力融合卷积神经网络

DPAFNet: A Residual Dual-Path Attention-Fusion Convolutional Neural Network for Multimodal Brain Tumor Segmentation DPAFNet:一种用于多模式脑肿瘤分割的残差双路径注意力融合卷积神经网络背景贡献实验方法ulti-scale context feature extraction block&…

Shell判断:流程控制—if(二)

一、多分支结构 1、语法: if 条件测试1 then 命令序列 elif 条件测试2 then 命令序列 elif 条件测试3 then 命令序列.... else 命令序列 fi 2、示例&am…

64位ATT汇编语言使用bss段.skip指令储存字符,并使用系统调用输出字符

.global main .section .data .section .bss# 需要输出的字符数组,还没有初始化mystring: .skip 4 .section .text main:# 将mystring这个字符串的地址存入到rbx寄存器中leaq mystring,%rbx# 将a放入到mystring第一个字节里边movb $a,(%rbx)# 将地址往后边移动一个字…

python算法例10 整数转换为罗马数字

1. 问题描述 给定一个整数,将其转换为罗马数字,要求返回结果的取值范围为1~3999。 2. 问题示例 4→Ⅳ,12→Ⅻ,21→XⅪ,99→XCIX。 3. 代码实现 def int_to_roman(num):val [1000, 900, 500, 400,100, 90, 50, 40…

树之手撕红黑树

简单说一下二叉搜索树与AVL树 要学红黑树,首先你必须学会二叉搜索树,也就是二叉查找树,如果不会的同学,可以去看我写过的文章里面有 那么这里我们来说一下AVL树 他就是一个平衡二叉搜索树,什么叫平衡呢,就…

大数据HCIE成神之路之数学(2)——线性代数

线性代数 1.1 线性代数内容介绍1.1.1 线性代数介绍1.1.2 代码实现介绍 1.2 线性代数实现1.2.1 reshape运算1.2.2 转置实现1.2.3 矩阵乘法实现1.2.4 矩阵对应运算1.2.5 逆矩阵实现1.2.6 特征值与特征向量1.2.7 求行列式1.2.8 奇异值分解实现1.2.9 线性方程组求解 1.1 线性代数内…

数据库课后习题加真题

文章目录 第二章第三章第四到六章某年真题 第二章 第三章 3.8 对于教学数据库的三个基本表: s( 学号 ‾ \underline{学号} 学号​,姓名,年龄, 性别) sc( 学号 , 课程号 ‾ \underline{学号, 课程号} 学号,课程号​, 成绩) c( 课程号 ‾ \un…

【Linux网络】详解使用http和ftp搭建yum仓库,以及yum网络源优化

目录 一、回顾yum的原理 1.1yum简介 yum安装的底层原理: yum的好处: 二、学习yum的配置文件及命令 1、yum的配置文件 2、yum的相关命令详解 3、yum的命令相关案例 三、搭建yum仓库的方式 1、本地yum仓库建立 2、通过http搭建内网的yum仓库 3、…

11 月 18 日 ROS 学习笔记——可视化和调试工具

文章目录 前言一、调试 ROS 节点1. gdb 调试器2. 在 ROS 节点启动时调用 gdb 调试器3. 在 ROS 节点启动时调用 valgrind 分析节点4. 设置 ROS 节点 core 文件转储5. 日志消息1). 输出日志消息2). 设置调试消息级别 二、检测系统状态1. rqt_graph2. 可视化坐标变换3. 保存与回放…

Leetcode—2760.最长奇偶子数组【简单】

2023每日刷题&#xff08;三十一&#xff09; Leetcode—2760.最长奇偶子数组 实现代码 #define MAX(a, b) ((a > b) ? (a): (b)) int longestAlternatingSubarray(int* nums, int numsSize, int threshold){int ans 0;int i 0;while(i < numsSize) {if(nums[i] >…

HUAWEI华为MateBook X 2020款i5集显(EUL-W19P)原装出厂Windows10系统

链接&#xff1a;https://pan.baidu.com/s/1eZuLjarWH2PjAWVqMWnzjQ?pwd2374 提取码&#xff1a;2374 原厂系统自带所有驱动、出厂主题壁纸、系统属性专属LOGO标志、Office办公软件、华为电脑管家等预装程序

迭代新品 | 第四代可燃气体监测仪,守护燃气管网安全快人一步

城市地下市政基础设施是城市有序运行的生命线&#xff0c;事关城市安全、健康运行和高质量发展。近年来&#xff0c;我国燃气事故多发、频发。2020、2021、2022 年分别发生燃气事故668、1140 起、802 起&#xff0c;造成92、106、66 人死亡&#xff0c;560、763、487 人受伤。尤…