Commits

lan Nomar  committed 097aef5

Works!

  • Participants

Comments (0)

Files changed (1)

File setcolor.brc

+#!/usr/bin/env brc
+
+Type=Normal
+
+flagfmt='h,f foreground,b background,t type' ; eval `{ getflags $* }
+
+if (~ $#* 0) { flagh=1 }
+if (~ ($#flagt $#flagb $#flagf) 1) { flagh=() }
+if (~ $flagh 1) { echo 'Sets a terminal color using the ansi color codes
+ setcolor <FG BG effect> <-f FG -b BG -t Type>
+  Colors:	Off	Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
+  Type:		Normal, Bold, Under or Lined, Blink, Same (BG=FG)
+' ; exit 0}
+
+fn Color {
+ switch($$1){
+  case [Bb]lack		;	$1=0
+  case [Rr]ed		;	$1=1
+  case [Gg]reen		;	$1=2
+  case [Yy]ellow	;	$1=3			
+  case [Bb]lue		;	$1=4			
+  case [Mm]agenta	;	$1=5
+  case [Cc]yan		;	$1=6			
+  case [Ww]hite		;	$1=7			
+  case [Oo]ff [Nn]^(one ull) ; printf '\033['^$Type^'m' ; exit 0
+  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 :)
+
+FgC=($flagf $1) ; if (~ $#FgC 1) { Color FgC ; Fg=3 ; Colors=';'^$Fg^$FgC }
+BgC=($flagb $2) ; if (~ $#BgC 1) { Color BgC ; Bg=4 ; Colors=$Colors^';'^$Bg^$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 }
+
+printf '\033['^$Type^$Colors
+#it works, but it shouldnt define ; or $[FB]g
+# should be possible to jump to the 2nd arg, setcolor -- blue