3.命令格式 tput [-Ttype] capname [parms ... ] tput [-Ttype] init tput [-Ttype] reset tput [-Ttype] longname tput -S << tput -V capname 是来自 terminfo 数据库的能力。 tput clear # 清屏 tput sc # 保存当前光标位置(save cursor position) tput cup 10 13 # 将光标移动到 row col tput civis # (tput sc ; tput cup 23 45 ; echo “Input from tput/echo at 23/45” ; tput rc) tput sc 保存当前的光标位置。 setb 6 tput setf 4 要反显当前的颜色方案,只需执行 tput rev。
github https://github.com/pedroqin/clock_by_tput 目的 通过简易时钟的实现,熟悉tput各功能参数 实现 主要实现功能(文末视频演示) 时钟功能(字符画显示 # 获取窗口大小 function terminal_size() { terminal_cols="$(tput cols)" terminal_rows="$(tput lines sgr0; tput cnorm; tput rmcup || clear; exit 0' SIGINT # 接收到 WINCH (窗口大小变化)信号,将变量置1 trap 'IF_WINCH=1' WINCH # 终端前景/背景颜色控制 BG_BLUE="$(tput setab 4)" FG_BLACK="$(tput setaf 0)" FG_WHITE="$(tput setaf 7)" man 5 terminfo tput(http://linuxcommand.org/lc3_adv_tput.php)
echo echo "Hostname is $(tput setaf 3)`hostname`$(tput sgr0),\ Ip address is $(tput setaf 3)\ `/sbin \ system is $(tput bold) `head -n 1 /etc/issue`\ $(tput sgr0), Nuclear info is $(tput setaf 1)\ ${nuclear }$(tput sgr0)." g'`$(tput sgr0)." (tput sgr0) threads."
脚本如下所示: p=1 f=75 s=13 r=2000 t=0 w=$(tput cols) h=$(tput lines) # ab -> idx = a*4 + b # 0: up, 1: right \n" exit 0;; esac done cleanup() { tput rmcup tput cnorm exit 0 } trap cleanup RANDOM*h/32768:h/2)) done tput smcup tput reset tput civis while ! 3:${n[i]}%4)) # Print: tput cup ${y[i]} ${x[i]} [[ $NOCOLOR == 0 ]] && echo reset && tput civis && t=0 || ((t++)) done cleanup 2.10 oneko 养只猫,你们看看,可以追着鼠标跑。
/bin/bash bold=$(tput bold) underline=$(tput sgr 0 1) reset=$(tput sgr0) red=$(tput setaf 1) green=$( tput setaf 76) white=$(tput setaf 7) tan=$(tput setaf 202) blue=$(tput setaf 25) underline() { printf
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. Backup" # Set bold mode tput bold tput cup 12 15 read -p "Enter your choice [1-4] " choice tput clear tput sgr0 tput rc 输出: ?
cols) h=$(tput lines) # ab -> idx = a*4 + b # 0: up, 1: right, 2: down, 3: left # 00 means going up \n" exit 0;; esac done cleanup() { tput rmcup tput cnorm exit 0 } trap cleanup RANDOM*h/32768:h/2)) done tput smcup tput reset tput civis while ! 3:${n[i]}%4)) # Print: tput cup ${y[i]} ${x[i]} [[ $NOCOLOR == 0 ]] && echo - c[i]}m" echo -n "${v:l[i]*4+n[i]:1}" l[i]=${n[i]} done ((r>0 && t*p>=r)) && tput
echo "$begin_x - $str_len / 2 "|bc` str_y=`echo "$begin_y - $line_num / 2 + $i "|bc` tput $str_line" done } function clean_env() { rm $flag_file 2>/dev/null # unhide cursor tput cnorm # reposit cursor tput cup $[height+1] 0 echo echo "finished." i in ${snakes[@]};do [ "$i" == "$egg_x,$egg_y" ] && has_egg=0 done done tput top_border="$top_border$border" second_border="$second_border$border" # hide cursor tput
shell脚本的颜色集成 set +e set -o noglob # # Set Colors # bold=$(tput bold) underline=$(tput sgr 0 1) reset =$(tput sgr0) red=$(tput setaf 1) green=$(tput setaf 76) white=$(tput setaf 7) tan=$(tput setaf 202) blue=$(tput setaf 25) # # Headers and Logging # underline() { printf "${underline}${bold}%s${reset
在有些情况,终端显示会混乱无比,比如不小心显示了一个二进制文件或使用 tput 进行了一些不符合预期的终端配置。在你不知道 reset 命令前,你可以将终端强行关闭,然后重新登录。 当然,你也可以使用tput reset命令重新初始化终端。 如果只是想清理屏幕内容,那么 clear 也可以。 注意:reset 其实是 tset 命令的软链。 比如通过 tput 命令将终端的背景颜色改为黄色,将前景颜色改为红色: tput setb 6; tput setf 4 那么现在使用 reset 便可恢复如初。 reset 或 tput reset (2)打印 set 命令设置 TERM 时的字符串。 reset -s TERM=xterm; (3)查看 reset 指向的真实命令。
tput clear #清屏 tput civis #隐藏光标 tput cnorm #不隐藏光标 tput cup #移动光标到屏幕位置(x,y) tput el #清除到行尾 tput ell #清除到行首 tput smso #启动突出模式 tput rmso #停止突出模式 tput smul #开始下划线模式 tput rmul #结束下划线模式 tput sc #保存当前光标位置 tput rc #恢复光标到最后保存位置 tput sgr0 #正常屏幕 tput rev #逆转视图 tput setaf #字符颜色 tput setab #背景颜色 #(2)数字输出参数设置 cols #列数目 echo $(tput setaf $i)"show me the money"$(tput sgr0) done printf '\n'$(tput setaf 2; tput setab 0; tput
/bin/bash COUNTER=0 _R=0 _C=`tput cols` _PROCEC=`tput cols` tput cup $_C $_R printf "[" while [ $ COUNTER=`expr $COUNTER + 1` sleep 0.1 printf "=>" _R=`expr $_R + 1` _C=`expr $_C + 1` tput cup $_PROCEC 101 printf "]%d%%" $COUNTER tput cup $_C $_R done printf "\n"
20 60 'XL' 30 20 90 ) function drawboard() { [[ "$dxt" ]] || { dxt=$mx; dyf=0; dyt=$my; } tput ]=12 (( bomb[j*mx+i]==0 && board[j*mx+i]==10 )) && board[j*mx+i]=13 done; done drawboard tput bomb[cy*mx+cx]==1 )) && { gameover; return; } [[ "$1" ]] || { dxt=$sx; dyf=$sy; dyt=$sy tput 'cup' 1 52 echo -n $'\e[43;30mB)\e[0m' status=0 } tput 'cup' 1 47 echo -en "\e[0m$mf " } # |\/| /\ | |\| newgame 'n' while :; do tput 'cup' $(( cy+2 )) $(( cx*2 )) echo -en
34.getconf LONG_BIT: 看linux是32位还是64位最简单的方法 35.while sleep 1;do tput sc;tput cup 0 (((tput cols)-29)); date;tput rc;done &:脚本在 shell / 终端的右上角输出日期和时间。
---- format, convert a folder, batch conversion support # Requirement: gcc ffmpeg # Colors RED="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" GREEN="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" YELLOW ="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" WHITE="$(tput setaf 7 2>/dev/null || echo '\e[0;37m ')" RESET="$(tput sgr 0 2>/dev/null || echo '\e[0m')" # Main cur_dir=$(cd `dirname $0`; pwd) if [ !
return self def __len__(self): return self.len def __next__(self): if self.tput_timer : self.tput_timer.start() return next(self.data) 样例 import torch import logging None, num_local_io_workers=None, data_sampler=None): self.tput_timer = tput_timer self.batch_size = batch_size if local_rank >= 0: # 开启分布式 用DistributedSampler : self.tput_timer.start() return next(self.data) def _create_dataloader(self
2967 cksum 2968 man cksum 2969 tput sc 2970 tput setb 6 2971 tput setf 4 2972 man tput 2973 reset 2974 man tput 2975 man terminfo 2976 man apropos 2977 hist 2978
parameters="" # the file is not in $dir not_dir=0 # show message in green function green_message() { tput bold echo -ne "\033[32m$@\033[0m" tput sgr0 echo } # show message in red function red_message () { tput bold echo -ne "\033[31m$@\033[0m" tput sgr0 echo } function isdigit() { Lines=66 MD5="e83f8ab79a1f0df0ef695030d6957066" # show message in green function green_message() { tput () { tput bold echo -ne "\033[31m$@\033[0m" tput sgr0 echo } # print description and
1.实例 l 获取终端的行数和列数: tput cols tput lines l 打印当前终端名: tput longname l 将光标移动到坐标(100,100)处: tput cup 100 100 l 设置终端背景色: tputsetb n 其中,n可以在0到7之间取值 l 设置文本样式为粗体 tput bold l 设置下划线的起止: tput smu1 tput rmu1 l 删除从当前光标位置到行尾的所有内容 count -lt 40 ]; then let count++; sleep 1; tput rc tput ed echo -n $count 用tput sc存储光标的位置。在每次循环中,通过恢复之前存储的光标的位置,在终端中打印出新的count的值。恢复光标的命令是tput rc。 tput ed清除从当前光标位置到行尾之间的所有内容,使得旧的count值可以被清除并写入新值。循环内的1秒钟延迟是通过sleep命令来实现。
error_num=`egrep '(error|Failed)' ${install_report} |wc -l` if [ $error_num == "0" ] then tput "----------------------------------------------------------------------------------------" tput sgr0 else tput bold echo "------------------------------------------------------ "----------------------------------------------------------------------------------------" tput