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)) }
}
}
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.
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. :)
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.
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.