30.2. tput

为输出着色

tput Color Capabilities:

tput setab [1-7] – Set a background color using ANSI escape
tput setb [1-7] – Set a background color
tput setaf [1-7] – Set a foreground color using ANSI escape
tput setf [1-7] – Set a foreground color

tput Text Mode Capabilities:

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 (bold on rxvt)
tput rmso – Exit standout mode
tput sgr0 – Turn off all attributes

Color Code for tput:

0 – Black
1 – Red
2 – Green
3 – Yellow
4 – Blue
5 – Magenta
6 – Cyan	
7 – White
		
NORMAL=$(tput sgr0)  
RED=$(tput setaf 1)  
GREEN=$(tput setaf 2; tput bold)  
YELLOW=$(tput setaf 3)  
BLUE=$(tput setaf 4) 
MAGENTA=$(tput setaf 5) 
CYAN=$(tput setaf 6) 
WHITE=$(tput setaf 7) 
   
function exception(){
	echo -e "$WHITE$*$NORMAL"
}

function critical() {  
    echo -e "$RED$*$NORMAL"  
}  
   
function info() {  
    echo -e "$GREEN$*$NORMAL"  
}  
   
function warning() {  
    echo -e "$YELLOW$*$NORMAL"  
}  
  
function error(){
	echo -e "$MAGENTA$*$NORMAL"
} 
 
function debug(){
	echo -e "$CYAN$*$NORMAL"
} 
 
# To print critical  
critical "kernel error"  

# To print exception 
exception "file system exception"
   
# To print error  
error "The configuration file does not exist"  
   
# To print warning  
warning "You have to use higher version."
	
# To print info  
info "Task has been completed."	

# To print debug 
debug "This is a debug message."
		

30.2.1. Change the prompt color using tput

$ export PS1="\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\]"			
		




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值