INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How can I colorize my help?

How can I colorize my help?

(OP)
I'm trying to create a colorful help for all the functions I'm creating...

I have the following ::--->

gethelp () {
cat << EOF
act ::---> Get one or more clients activity. act <Client_name or Client_list>
his ::---> Get one or more client backup history. his <Client_name or Client_list>
logs ::---> Get logs for one or more clients. logs <Client_name or Client_list>
cl ::---> Generate a client list. cl
gf ::---> Get clients failures from the past 2 days. gf
csv ::---> Generate a csv file containing all clients. csv
cc ::---> Generate a csv file for one or many clents. cc <Client_name or Client_list>
tbw ::---> Test Backup for a windows client. tbw <Client_name>
gln ::---> Get Label number for the last backup. gln <Client_name>
wgbu ::---> What got backed up. wgbu <label_number> </Domain/Client_name>
ptf ::---> Perform the test restore. ptf <label_number> </Domain/Client_name>
gip ::---> Get ip for one or many clients. gip <Client_name or Client_list>
cu ::---> Client usage for one or many clients. cu <Client_name or Client_list>
EOF
}

I would like to make the 1st column from the left bold..

And a separate color for the following ::--->

::--->
Everything up to the period
From the period to the end

Thanks.....

Joe Despres

RE: How can I colorize my help?

Hi

This colorizes the text only if the output goes to the terminal. So if gets redirected, the plain version is output ( for example so you can grep in it ) :

CODE --> Bash, Dash, (M)Ksh

gethelp()
{
  {
    [ -t 1 ] &&
    sed 's/^\(\w\+\)\(\s\+\)\(::--->\)\(\s\+\)\([^.]*.\)\(\s\+\)\(.*\)$/^[[31m\1^[[0m\2^[[32m\3^[[0m\4^[[33m\5^[[0m\6^[[34m\7^[[0m/' ||
    cat
  } << EOF
act ::---> Get one or more clients activity. act <Client_name or Client_list>
his ::---> Get one or more client backup history. his <Client_name or Client_list>
logs ::---> Get logs for one or more clients. logs <Client_name or Client_list>
cl ::---> Generate a client list. cl
gf ::---> Get clients failures from the past 2 days. gf
csv ::---> Generate a csv file containing all clients. csv
cc ::---> Generate a csv file for one or many clents. cc <Client_name or Client_list>
tbw ::---> Test Backup for a windows client. tbw <Client_name>
gln ::---> Get Label number for the last backup. gln <Client_name>
wgbu ::---> What got backed up. wgbu <label_number> </Domain/Client_name>
ptf ::---> Perform the test restore. ptf <label_number> </Domain/Client_name>
gip ::---> Get ip for one or many clients. gip <Client_name or Client_list>
cu ::---> Client usage for one or many clients. cu <Client_name or Client_list>
EOF
} 
Tested with Bash, Dash and MKsh.

Unless this is the only place you need it, i would think to develop a generic way to do this.

Feherke.
http://feherke.github.com/

RE: How can I colorize my help?

(OP)
hhhhmmmmm

I must of copied wrong...

I'm getting a bunch of characters before and after..

Thanks!

Joe Despres

RE: How can I colorize my help?

Hi

Maybe because I forgot to add the explanation : the ^[ in the text are ESC ( \e, \033, \x1b ) characters. You type them as Ctrl-v,Esc. So the "^[" is only the displayed image of the character, you can not get the character itself by by copy & pasting its displayed image. ( The way to type such characters may depend on the editor you use. For example in Midnight Commander's built-in editor you have to type Ctrl-q,Esc,Esc. )

To avoid typing ESC characters, you can use this code instead, but I am not sure whether is understood by other implementations than GNU sed :

CODE

sed 's/^\(\w\+\)\(\s\+\)\(::--->\)\(\s\+\)\([^.]*\.\)\(\s\+\)\(.*\)$/\o033[31m\1\o033[0m\2\o033[32m\3\o033[0m\4\o033[33m\5\o033[0m\6\o033[34m\7\o033[0m/' 
Or if you use Bash, you can use it to interpret the escape sequences :

CODE

sed -r $'s/^(\\w+)(\\s+)(::--->)(\\s+)([^.]*\\.)(\\s+)(.*)$/\e[31m\\1\e[0m\\2\e[32m\\3\e[0m\\4\e[33m\\5\e[0m\\6\e[34m\\7\e[0m/' 

Feherke.
http://feherke.github.com/

RE: How can I colorize my help?

Hi

Quote (PHV)

Why not simply use the tput command ?
1) Personal habit since DOS times; 2) never found a good documentation; 3) speed consideration.

By the way, how would you use tput in this case ? In the sed code like I used the ANSI escapes or directly in the cated text ?

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close