Commits

lan Nomar  committed 475a3c8

Added a License

  • Participants
  • Parent commits 5d5465a

Comments (0)

Files changed (2)

+Copyright (c) 2011, Khwerz@gmail.com
+
+Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+

File setcolor.brc

 #!/usr/bin/env brc
 
-Type=Normal
+fn OFS { lflat=$*; *=$$1 ; while () { echo -n $1; shift ; ~ $#* 0 && break ; echo -n $lflat(2) } }
 
 flagfmt='h,f foreground,b background,t type' ; eval `{ getflags $* }
 
 
 fn Color {
  switch($$1){
-  case [Bb]la* [Dd]*;	$1=0	# Black Dark
-  case [Rr]*		;	$1=1	# Red
-  case [Gg]*		;	$1=2	# Green
-  case [Yy]*		;	$1=3	# Yellow
-  case [Bb]lu*		;	$1=4	# Blue
-  case [Mm]*		;	$1=5	# Magenta
-  case [Cc]*		;	$1=6	# Cyan
-  case [Ww]*		;	$1=7	# White
-  case [Oo]*		;	printf '\033['^$Type^'m' ; exit 0 #Off
-  case [Nn]*		;	$1=() #(one ull)
-  case *			;	echo 'No such color' ; exit 1 } }
+  case [Bb]la* [Dd]a*	;	$1=0	# Black Dark
+  case [Rr]*			;	$1=1	# Red
+  case [Gg]*			;	$1=2	# Green
+  case [Yy]*			;	$1=3	# Yellow
+  case [Bb]lu*			;	$1=4	# Blue
+  case [Mm]*			;	$1=5	# Magenta
+  case [Cc]*			;	$1=6	# Cyan
+  case [Ww]*			;	$1=7	# White
+  case [Dd]e*			;	$1=9	# Default
+  case [Oo]*			;	printf '\033['^$Type^'m' ; exit 0 #Off
+  case [Nn]*			;	$1=() #(one ull)
+  case *				;	echo 'No such color' ; exit 1 } }
 
-if(~ $#flagt 1){Type=$flagt	} else {
- if (~ $#* 3) {	Type=$3		} }
-
-switch($Type){ # type is mandatory
-  case [Nn]ormal		;	Type=0
-  case [Bb]old			;	Type=1
-  case [Uu]* [Ll]ined	;	Type=4
-  case [Bb]link			;	Type=5
-  case [Ss]* [Ll]ight	;	Type=7 # because the font col bg, becomes a bit light
-  case [01457]			;	Type=$Type
-  case *				;	Type=0 }
-
-# i literally spent a whole day for this 5 lines :)
+Type=($flagt $3) ; if (~ $#Type 1) {
+switch($Type){
+  case [Nn]*			;	Type=0	# Normal
+  case [Bb]o*			;	Type=1	# Bold
+  case [Uu]* [Ll]*		;	Type=4	# UnderLined
+  case [Bb]l*			;	Type=5	# Blink
+  case [Ss]* [Rr]*		;	Type=7	# Swap Reverse  (Inverse Unsupported)
+  case [Ii]*			;	Type=8	# Invisible
+  case [Bb]r*			;	Type=10	# Bright
+  case *[01457]*		;	Type=$Type
+  case *				;	Type=() } }
 
 FgC=($flagf $1)		; ~ $#FgC 1 && Color FgC
-	if (~ $#FgC 1) { Fg=3 ; Colors=';'^$Fg^$FgC }
+	if (~ $#FgC 1) { Fg=3^$FgC }
 BgC=($flagb $2)		; ~ $#BgC 1 && Color BgC
-	if (~ $#BgC 1) { Bg=4 ; Colors=$Colors^';'^$Bg^$BgC }
+	if (~ $#BgC 1) { Bg=4^$BgC }
 
 if (~ $#Bg 1){ if (~ $#Fg 0) { Type=7 } } # Cant set Bg without Fg, unless you set type=7
 
-if (!~ $Colors *m) { Colors=$Colors^m }
+o=($Type $Fg $Bg) ; o=`{ OFS o ';' }
 
-printf '\033['^$Type^$Colors
+printf '\033['^$o^m