|
|
第 1 帖 | |
|
|
标题: javalee兄!教教那个控制太的彩色显示! 比如这样的PS1="\[\033[1;34m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0;37m\] "
里面那些[\033[0;37m的代码 |
|
|
|
|
|
|
|
第 2 帖 | |
|
|
to Freebird
我很少在字符下使用什么颜色 ![]() 不过你看看下面的链接,不知道是否对你有帮助 ![]() http://www.linuxsir.com/bbs/showthre...t=%C4%A7%CA%F5 |
|
|
|
|
|
|
|
第 3 帖 | |
|
|
Freebird兄,我说一下不知道给不给呵~~~~~,抢了javalee兄的风头,不好意思
使用颜色: 使用色彩需要在echo语句中嵌入控制字符,只要是带有彩色终端的系统都可以使用, 我们知道在linux里用echo语句用选项-e可以使转义的字符产生效果,(ps:Freebird兄爱好的FreeBSD也是这样的,但在System V中不一样,不用使用-e选项),也可以不使用-e选项,但要这样做ctrl+v,之后按ESC,得到转义序列(这句为什么这样我也不懂????:( ,有兄弟懂的指点一下啊?!谢谢!! )使用终端颜色(前景和背景)的格式为: ^[ [背景色代码;前景色代码m 或是 \033[背景色代码;前景色代码m 其中^[要这样产生ctrl+v,之后按ESC. 一些常用的颜色代码:(这些颜色是ANSI标准颜色) 前景色:30黑 31红 32绿 33黄 34蓝 35紫 36青 37白 背景色:40黑 41红 42绿 43黄 44青 45蓝 46青 47白 举个例子,可以这样做马上使终端的行变成红后绿前 #echo '^[[41;32m' #echo "^[[41;32m" #echo -e "\033[41;32m" #echo -e '\033[41;32m' 以上四种方法都是可以的 要定制自己的颜色终端,可以把上面的类似行加入到.bash_profile中去,每次启动终端后都会是自己定制的颜色了。 我曾经写过一个失败的脚本, http://www.linuxsir.com/bbs/showthre...ight=100%CC%FB 里面有一个函数是color(),定制了几种颜色,有兴趣的兄弟可以看看那个函数 虽然整个脚本是失败的,但那个函数可不是失败的,不要误解啊!! 最后,倒要请教javalee兄整理一下关于转义字符方面的内容,以上的几种方式为什么都可以,我其实是不明白的,有没有这方面的内容介绍啊?! ![]()
__________________
深邃的技术不仅表现在敏捷的思维和高超的本领,还有过人的修养。 |
|
|
|
|
|
|
|
第 4 帖 | |
|
|
附带说一下,那个PS1的不懂:(
惭愧!!!! |
|
|
|
|
|
|
|
第 5 帖 | |
|
|
我系统(RH)中有个文件:/etc/termcap,看看它吧~~(E文的:()
PS1,主提示符. (我更惭愧) 此帖于 03-09-29 23:37 被 KornLee 编辑. |
|
|
|
|
|
|
|
第 6 帖 | |
|
|
YES!!!主提示符,真是惭愧,我隐约记起我看过这方面的介绍,可惜不全,忘的也快
E文?惨,硬着头皮看了(正好我的也是RH) |
|
|
|
|
|
|
|
第 7 帖 | ||
|
|
这个帖子里有详细的序列转义的说明
http://www.linuxsir.com/bbs/showthre...t=%C4%A7%CA%F5 而 引用:
cat /etc/DIR_COLORS文件则介绍了不同的颜色转义序列值 |
||
|
|
|
||
|
|
第 8 帖 | |
|
|
标题: 感动ing,javalee兄的责任心和无比的耐心~~~~ 谢谢指教!!认真阅读ing
|
|
|
|
|
|
|
|
第 9 帖 | |
|
|
感谢两位大哥!!
大恩铭记在心,感动ing........呵呵,这个极好!此帖于 03-09-30 08:38 被 Freebird 编辑. |
|
|
|
|
|
|
|
第 10 帖 | |
|
|
As mentioned before, non-printing escape sequences have to be enclosed in \[\033[ and \]. For colour escape sequences, they should also be followed by a lowercase m.
If you try out the following prompts in an xterm and find that you aren't seeing the colours named, check out your ?/.Xdefaults file (and possibly its bretheren) for lines like "XTerm*Foreground: BlanchedAlmond". This can be commented out by placing an exclamation mark ("!") in front of it. Of course, this will also be dependent on what terminal emulator you're using. This is the likeliest place that your term foreground colours would be overridden. To include blue text in the prompt: PS1="\[\033[34m\][\$(date +%H%M)][\u@\h:\w]$ " The problem with this prompt is that the blue colour that starts with the 34 colour code is never switched back to the regular gray, so any text you type after the prompt is still in the colour of the prompt. This is also a dark shade of blue, so combining it with the bold code might help: PS1="\[\033[1;34m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0;37m\] " The prompt is now in light blue, and it ends by switching the colour back to gray, which is the colour most of us expect to type in. Note: I should point out that, if you're working in an Xterm, and you've set your colours with something like "xterm -bg midnightblue -fg yellow", switching the colour back as I've described above over-rides the "-fg" that you used. I'm not aware of a way around this, please let me know if you have a solution. If you use a light-coloured background in your xterms, the gray text used above may be unreadable. If you want to use a prompt on both the console and xterms, but you use light background in your xterms, you may have to do some colour setting with a "case $TERM in ..." as shown in the Title Bar section. Here are the rest of the colour equivalences: Black 0;30 Dark Gray 1;30 Blue 0;34 Light Blue 1;34 Green 0;32 Light Green 1;32 Cyan 0;36 Light Cyan 1;36 Red 0;31 Light Red 1;31 Purple 0;35 Light Purple 1;35 Brown 0;33 Yellow 1;33 Light Gray 0;37 White 1;37 You can also set background colours by using 44 for Blue background, 41 for a Red background, etc. There are no bold background colours. Combinations can be used, like Light Red text on a Blue background: \[\033[44;1;31m\], although setting the colours separately seems to work better (ie. \[\033[44m\]\[\033[1;31m\]). Other codes available include 4: Underscore, 5: Blink, 7: Inverse, and 8: Concealed. Based on a prompt called "elite2" in the Bashprompt package (which I have modified to work better on a standard console, rather than with the special xterm fonts required to view the original properly), this is a prompt I've used a lot: function elite { local GRAY="\[\033[1;30m\]" local LIGHT_GRAY="\[\033[0;37m\]" local CYAN="\[\033[0;36m\]" local LIGHT_CYAN="\[\033[1;36m\]" case $TERM in xterm*) local TITLEBAR='\[\033]0;\u@\h:\w\007\]' ;; *) local TITLEBAR="" ;; esac local GRAD1=$(tty|cut -d/ -f3) PS1="$TITLEBAR\ $GRAY-$CYAN-$LIGHT_CYAN(\ $CYAN\u$GRAY@$CYAN\h\ $LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\ $CYAN\#$GRAY/$CYAN$GRAD1\ $LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\ $CYAN\$(date +%H%M)$GRAY/$CYAN\$(date +%d-%b-%y)\ $LIGHT_CYAN)$CYAN-$GRAY-\ $LIGHT_GRAY\n\ $GRAY-$CYAN-$LIGHT_CYAN(\ $CYAN\$$GRAY:$CYAN\w\ $LIGHT_CYAN)$CYAN-$GRAY-$LIGHT_GRAY " PS2="$LIGHT_CYAN-$CYAN-$GRAY-$LIGHT_GRAY " } I define the colours as temporary shell variables in the name of readability. It's easier to work with. The "GRAD1" variable is a check to determine what terminal you're on. Like the test to determine if you're working in an Xterm, it only needs to be done once. The prompt you see look like this, except in colour: --(giles@nikola)-(75/ttyp7)-(1908/12-Oct-98)-- --($:~/tmp)-- |
|
|
|
|
|
|
|
第 11 帖 | |
|
|
哈哈~~~在你们的悉心教导下,终于有了进步,下面是效果:
|
|
|
|
|
|
|
|
第 12 帖 | |
|
|
标题: 请版主把原贴标题适当修改好,设为精华贴。 谢谢三位,我一直在找这些东西
![]()
__________________
ASUSW3Z-W3HT30: TruionMT-30 1MB L2, 14.0'WXGA 1280x768,X200M,512MB+1GB-DDR333 DELLLattitudeD630: Core2 Duo T9300 6MB L2, 14.0'WXGA 1440x900, NVS 135M, 2GBx2-DDR667 ThinkPadX617675C: Core2 Duo L7500 3MB L2, 12.0'VGA 1024x768, GMA X3100, 2GBx2-DDR667 DELLOPTIPLEX-755: Core2 Duo E7200 3MB L2, 17"VGAx2 1280x1024, ATIHD 3400, 1GBx2-DDR667 KDE: http://www.kde.org/support/donations.php PSQL: http://www.postgresql.org/about/donate WQY: http://wenq.org/index.cgi?Donation |
|
|
|
|
|
|
|
第 13 帖 | |
|
|
标题: 补充一点.免得新手的出问题. PS1='\[\033[0;31m\][\u@\h:\w]\[\033[1;34m\]$\[\033[0;m\] '
~~~~~~~~~~恢复原来默认的 |
|
|
|
|
|
|
|
第 14 帖 | ||
|
|
标题: 回复: 请版主把原贴标题适当修改好,设为精华贴。 引用:
|
||
|
|
|
||