$coloring

By Scakk on Aug 26, 2008

Simple alias that allows you to add 1 color ( or back ground color ) with the ability to bold , underline or both to it.

/
Usage:
-- $coloring(TEXT,X,Y) = Text in color X ( 0-15 ) with background color Y ( 0-15 ).
-- $coloring(TEXT,X,Y).b = Text in color X ( 0-15 ) with background color Y ( 0-15 ) Bolded.
-- $coloring(TEXT,X,Y).u = Text in color X ( 0-15 ) with background color Y ( 0-15 ) Underlined.
-- $coloring(TEXT,X,Y).bu = Text in color X ( 0-15 ) with background color Y ( 0-15 ) Underlined and Bolded. ( also .ub )
/

Example: echo -a $coloring(test,4,12)

http://www.hawkee.com/snippet/5009/ <-- $unstrip alias

/*
Usage:
-- $coloring(TEXT,X,Y) = Text in color X ( 0-15 ) with background color Y ( 0-15 ).
-- $coloring(TEXT,X,Y).b = Text in color X ( 0-15 ) with background color Y ( 0-15 ) Bolded. 
-- $coloring(TEXT,X,Y).u = Text in color X ( 0-15 ) with background color Y ( 0-15 ) Underlined. 
-- $coloring(TEXT,X,Y).bu = Text in color X ( 0-15 ) with background color Y ( 0-15 ) Underlined and Bolded. ( also .ub )
*/
alias coloring {
  if ($isid && $2 isnum 0-15 && $3 isnum 0-15) {
    if (!$prop) { return $+($chr(3),$2,$chr(44),$3,$1,$chr(15)) }
    else { return $+($iif(b isin $prop,$chr(2)),$iif(u isin $prop,$chr(31)),$chr(3),$2,$chr(44),$3,$1,$chr(15)) } 
  }
}

Comments

Sign in to comment.
Epik-Fail   -  Sep 26, 2008

nice script oh i almost forgot

/me pokes Gummo XD

 Respond  
EL   -  Aug 28, 2008

Neat Scakk;p

 Respond  
vaseline28   -  Aug 27, 2008

Useful, and as you said on IRC, you're shortening it. As I said, I like the way in which you've constructed the script so that you can use a $prop in any order and the script will evaluate them all!

 Respond  
Gummo   -  Aug 27, 2008

I never said it was hard, but yeah. :)

 Respond  
Typo   -  Aug 27, 2008

Well thats easy enough, in my example the changed code would be:

alias colorit { if ($isid) && ($1 isnum 0-15) && ($2 isnum 0-15) { return $iif(b isin $prop,) $+ $iif(u isin $prop,) $+  $+ $iif($1 isnum 0-9,0) $+ $round($1) $+ $chr(44) $+ $iif($2 isnum 0-9,0) $+ $round($2) $+ $3- $+ $iif(b isin $prop,) $+ $iif(u isin $prop,) $+  } }

That just uses the same $iif's that set the b or u to unset them and throws a control+k at the end instead of the control+o.

 Respond  
Gummo   -  Aug 27, 2008

I personally think you should only end what you started in there (bold/underline/colour), rather than ctrl+o, but that's just me. :)

 Respond  
Scakk   -  Aug 27, 2008

Updated it and shortened it a bit ;)

Thanks for the tips Typo.

goes to shorten the $unstrip one also

 Respond  
Typo   -  Aug 27, 2008

I forgot the contro+o code at the end.

Here it is fixed to work like u were saying it wouldnt.

alias colorit { if ($isid) && ($1 isnum 0-15) && ($2 isnum 0-15) { return $iif(b isin $prop,) $+ $iif(u isin $prop,) $+  $+ $iif($1 isnum 0-9,0) $+ $round($1) $+ $chr(44) $+ $iif($2 isnum 0-9,0) $+ $round($2) $+ $3- $+  } }

That should do it. :)

 Respond  
Scakk   -  Aug 27, 2008

Typo .. Thanks for the feedback and ideas for shortening the code a bit. I will look into shortening it a bit and update it.

However using your version it does not end the bold , underline or color.

I used

//echo -a $colorit(04,5,test) test

And it colored both words instead of just the one. It did that for $prop 's as well.

 Respond  
Typo   -  Aug 27, 2008

This seams like overkill in way too many ways to mention. In just a couple minutes I came up with a one line alias to do almost the same thing.

Mine works like yours mostly except it requires both foreground and background colors.

I didnt think that was a big deal because your code and therefore my alternate code are only to be used as identifiers and its safe to assume that someone using an identifier can be trusted to include two colors.

My example is not trying to out do your code. Im simply trying to show you that theres differen ways of going about things that will help keep the size down.

Remember, mine works like $ColorIt(Color1,Color2,Text).bu such as $colorit(4,1,Hello people).ub

alias colorit { if ($isid) && ($1 isnum 0-15) && ($2 isnum 0-15) { return $iif(b isin $prop,) $+ $iif(u isin $prop,) $+  $+ $iif($1 isnum 0-9,0) $+ $round($1) $+ $chr(44) $+ $iif($2 isnum 0-9,0) $+ $round($2) $+ $3- } }

That code makes sure that the alias was called as an identifier and that both provided numbers are 0-15. It uses round to make sure that when it adds the 0 to the numbers 0-9 it woudnt end up with 009 for instance. It does some quick checks on $prop for the bold and underline and you end up with the text returned as wanted.

I hope this helps you with some ideas on how to improve your code.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.