Skip to content

Commit

Permalink
implements #7
Browse files Browse the repository at this point in the history
  • Loading branch information
betafcc committed May 16, 2021
1 parent 8018ac9 commit 98e06ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ clc '<red:hello <reverse:world>'
clc '<red:hello>'
clc '<green:hello <blue: world>>'
clc '<rgb 255 120 120: hello>'
clc '<rgb 255 120 120: hello>'
clc '<#f66: hello>'
clc '<#66fa73: hello>'
```

### Use background colors:
Expand All @@ -48,6 +51,7 @@ clc '<rgb 255 120 120: hello>'
clc '<bg red:hello>'
clc '<bg green:hello <bg blue: world>>'
clc '<bg rgb 255 120 120: hello>'
clc '<bg #66fa73: hello>'
```

### Use effects:
Expand All @@ -73,6 +77,8 @@ clc '<red + bg blue + underline + bold:hello>'
- cyan
- white
- rgb <0-255> <0-255> <0-255>
- #000 - #fff
- #000000 - #ffffff

### Available effects:
- normal
Expand Down
11 changes: 6 additions & 5 deletions clc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clc() {
clc_parse
else
case "${1}" in
-v|--version) echo 'v1.1.2';;
-v|--version) echo 'v1.2.0';;
-e|--escape) shift; clc "$@" | sed -E 's,(\x1B\[[0-9;]*[a-zA-Z]),\\\[\1\\\],g';;
*) printf '%s' "$@" | clc
esac
Expand All @@ -26,10 +26,10 @@ clc_parse() (
)

clc_parse_directive() (
IFS= read -r -d ':' directives;
IFS=+
for directive in ${directives}; do
eval "clc_code_$(printf ${directive} | xargs)"
IFS=+ read -r -d ':' -a directives;
for directive in "${directives[@]}"; do
directive=(${directive//\#/rgbhex })
eval clc_code_${directive[@]}
done | paste -sd ';' -
)

Expand All @@ -42,6 +42,7 @@ clc_code_magenta() { echo 35; }
clc_code_cyan() { echo 36; }
clc_code_white() { echo 37; }
clc_code_rgb() { echo "38;2;${1};${2};${3}"; }
clc_code_rgbhex() { eval clc_code_rgb $(echo $1 | sed -E -e 's/^(.)(.)(.)$/\1\1\2\2\3\3/;s/.{2}/$((16#&)) /g'); }

clc_code_bg() {
local fg="$(clc_code_"${@}")"
Expand Down

0 comments on commit 98e06ed

Please sign in to comment.