首页 > 其他分享 >(转)tput命令行使用说明

(转)tput命令行使用说明

时间:2023-11-24 11:37:09浏览次数:24  
标签:bin tput 颜色 bold color 说明 命令行 光标

tput 命令行使用说明

https://blog.csdn.net/fdipzone/article/details/9993961

1.tput简介
tput可以更改终端功能,如移动或更改光标,更改文本属性,清除终端屏幕的特定区域等。

2.命令行使用说明
2.1光标属性
tput clear #清除屏幕
tput sc #记录当前光标位置
tput rc #恢复光标到最后保存位置
tput civis #光标不可见
tput cnorm #光标可见
tput cup x y #光标按设定坐标点移动

2.2文本属性
tput blink #文本闪烁
tput bold #文本加粗
tput el #清除到行尾
tput smso #启动突出模式
tput rmso #停止突出模式
tput smul #下划线模式
tput rmul #取消下划线模式
tput sgr0 #恢复默认终端
tput rev #反相终端

2.3 颜色

2.3.1 文本颜色

tput setb 颜色代号
tput setf 颜色代号
颜色代号
0:黑色
1:蓝色
2:绿色
3:青色
4:红色
5:洋红色
6:黄色
7:白色

2.3.2 背景颜色

1. 前景色:
数字颜色数字颜色
0 黑色 4 蓝色
1 红色 5 紫色
2 绿色 6 青色
3 黄(或棕)色 7 白(或灰)色

2. 背景色:
数字颜色数字颜色
0 黑色 4 青色
1 红色 5 蓝色
2 绿色 6 青色
3 黄(或棕)色 7 白(或灰)色

例子:黑底绿字echo "33[40;32m"

利用上面参数编写一个终端时钟

#!/bin/bash

for ((i=0;i<10;i++))
do
        tput sc; tput civis                     #记录光标位置,及隐藏光标
        echo -ne $(date +'%Y-%m-%d %H:%M:%S')   #显示时间
        sleep 1
        tput rc                                 #恢复光标到记录位置
done

tput el; tput cnorm                             #退出时清理终端,恢复光标显示

4.现在为"终端时钟"添加,变换颜色和闪烁功能

#!/bin/bash

for ((i=0;i<8;i++))
do
        tput sc; tput civis                     #记录光标位置,及隐藏光标
        tput blink; tput setf $i                #文本闪烁,更改文本颜色
        echo -ne $(date +'%Y-%m-%d %H:%M:%S')   #显示时间
        sleep 1
        tput rc                                 #恢复光标到记录位置
done

tput el; tput cnorm                             #退出时清理终端,恢复光标显示

5.使输出的字符串有颜色,底色,加粗

#!/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

6.输出格式控制函数

#!/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

7.总结
tput sc #记录光标位置
tput cup x y #移动光标至x列y行
tput rc #返回光标位置
tput civis #隐藏光标
tput cnorm #示光标
tput setaf ColorNumber #设置前景色
tput setab ColorNumber #设置背景色

 

转自:版权声明:本文为CSDN博主「东城绝神」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_37814112/article/details/103159605

 

标签:bin,tput,颜色,bold,color,说明,命令行,光标
From: https://www.cnblogs.com/Cong0ks/p/17853339.html

相关文章

  • 工作流引擎的主要表结构及其作用如下,下面以驰骋工作流引擎为例来说明。
     1.WF_GenerWorkFlow:该表主要用于存储流程引擎级别的数据,发起人,发起日期,workid,流程状态,流程标题,运行到的节点。2.WF_GenerWorkerList::这个表主要用于保存工作人员数据,执行人、执行节点、工作ID,是否读取,是否通过IsPass,.3.NDxxRpt*:业务数据表,表单采集的业务数据。。4.Port_*......
  • ESP 8266 RELAY V3 调试说明
    ESP8266继电器模块V3是一个非常方便的设备,可以用于控制各种类型的继电器。以下是调试该模块的一些说明:连接设备:首先,将ESP8266继电器模块V3连接到计算机或其他调试设备上。您可以使用USB转TTL串口线来连接设备。确保正确连接并给设备上电。配置设备:在开始调试之前,您需要配置ESP8266......
  • 【最新最全指南】Vue项目安装eslint配置说明
    本指南都适配windows和mac下的开发项目第一步:安装1、全局安装:eslint(最好全局安装1个,配置出错debug方便)npminstalleslint-g2、项目本地dev安装:eslint(也可不安装,后面安装eslint-plugin-vue时候,默认会一起安装eslint)npminstalleslint-D3、项目本地dev安装插件:eslint-plu......
  • 231103 - i18n Ally 国际化插件使用说明
    231103-i18nAlly国际化插件使用说明i18nAlly国际化插件使用说明搜索安装插件;在项目下的settings.json加入如下配置,localesPaths要结合项目目录进行配置;"i18n-ally.annotationInPlace":false,"i18n-ally.displayLanguage":"zh-chs","i18n-ally.sour......
  • 命令行非交互式发送邮件ForWindows
    2个工具Cmail(更加推荐):https://www.inveigle.net/cmail发现的问题:如果需要调用外部txt作为邮件的body部分,那么该文本编码必须为utf-8下载:https://www.inveigle.net/cmail/download最佳配置实践:https://www.inveigle.net/cmail/examples Blat:https://www.blat.net/下载:https......
  • 富文本框tinymce参数说明
    文档:http://tinymce.ax-z.cn/plugins/imagetools.php{language:_this.language,//显示语种selector:#${_this.tinymceId},//容器的idheight:_this.height,//高度body_class:'panel-body',object_resizi......
  • Tcp常见配置参数说明
    socket=newSocket();//TIME_WAIT状态下可以复用端口socket.setReuseAddress(true);//空闲时发送数据包,确认服务端状态socket.setKeepAlive(true);//关闭Nagle算法,尽快发送socket.setTcpNoDelay(true);//调用close方法立即关闭socket,丢弃所有未发送的数据包sock......
  • change windows cmd prompt 修改windows命令行提示符
    通过修改环境变量控制cmd提示符。 refcmd-HowdoIchangethecommand-linepromptinWindows?-StackOverflowhttps://stackoverflow.com/questions/12028372/how-do-i-change-the-command-line-prompt-in-windowsAbetterPROMPTforCMD.EXEorCoolPromptEnv......
  • Tmux 终端命令行介绍
    一、 命令介绍: Tmux("TerminalMultiplexer"的简称),是一款优秀的终端复用软件,类似 GNUscreen,但比screen更出色。tmux来自于OpenBSD,采用BSD授权。使用它最直观的好处就是,通过一个终端登录远程主机并运行tmux后,在其中可以开启多个控制台而无需再“浪费”多余的终端来连接......
  • huggingface下载的.arrow数据集读取与使用说明
    huggingface下载的.arrow数据集读取与使用说明fromdatasetsimportload_from_diskfromdatasetsimportload_datasetdataset_cnn=load_dataset("ccdv/cnn_dailymail",'3.0.0',cache_dir=&qu......