Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I colorize my help? 1

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
0
0
US
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

 
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 [tt]grep[/tt] in it ) :
Code:
[COLOR=darkgoldenrod]gethelp()[/color]
{
  {
    [teal][[/teal] -t [purple]1[/purple] [teal]][/teal] [teal]&&[/teal]
    sed [green][i]'s/^\(\w\+\)\(\s\+\)\(::--->\)\(\s\+\)\([^.]*.\)\(\s\+\)\(.*\)$/[COLOR=lime black]^[[/color][31m\1[COLOR=lime black]^[[/color][0m\2[COLOR=lime black]^[[/color][32m\3[COLOR=lime black]^[[/color][0m\4[COLOR=lime black]^[[/color][33m\5[COLOR=lime black]^[[/color][0m\6[COLOR=lime black]^[[/color][34m\7[COLOR=lime black]^[[/color][0m/'[/i][/green] [teal]||[/teal]
    cat
  } [teal]<<[/teal] 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.
[link feherke.github.com/][/url]
 
hhhhmmmmm

I must of copied wrong...

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

Thanks!

Joe Despres
 
Hi

Maybe because I forgot to add the explanation : the [tt][COLOR=lime black]^[[/color][/tt] in the text are ESC ( [tt]\e[/tt], [tt]\033[/tt], [tt]\x1b[/tt] ) characters. You type them as [kbd]Ctrl[/kbd]-[kbd]v[/kbd],[kbd]Esc[/kbd]. 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 [kbd]Ctrl[/kbd]-[kbd]q[/kbd],[kbd]Esc[/kbd],[kbd]Esc[/kbd]. )

To avoid typing ESC characters, you can use this code instead, but I am not sure whether is understood by other implementations than GNU [tt]sed[/tt] :
Code:
sed [green][i]'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/'[/i][/green]
Or if you use Bash, you can use it to interpret the escape sequences :
Code:
sed -r $[green][i]'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/'[/i][/green]

Feherke.
[link feherke.github.com/][/url]
 
Why not simply use the tput command ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

PHV said:
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 [tt]tput[/tt] in this case ? In the [tt]sed[/tt] code like I used the ANSI escapes or directly in the [tt]cat[/tt]ed text ?


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top