From 8018ac9befa2000c6ea324722493adfd5e931ed9 Mon Sep 17 00:00:00 2001 From: Beta Faccion Date: Tue, 19 May 2020 00:38:43 +0100 Subject: [PATCH] removes bundling --- Makefile | 4 -- clc | 179 +++++++++++++++------------------------------- make_bundle | 14 ---- src/clc.bash | 32 --------- src/clc_code.bash | 31 -------- test_example.bash | 17 ----- 6 files changed, 56 insertions(+), 221 deletions(-) delete mode 100644 Makefile delete mode 100755 make_bundle delete mode 100644 src/clc.bash delete mode 100644 src/clc_code.bash delete mode 100644 test_example.bash diff --git a/Makefile b/Makefile deleted file mode 100644 index db22227..0000000 --- a/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -clc: src/*.bash - env -i ./make_bundle $^ > $@ - chmod +x $@ -.DELETE_ON_ERROR: diff --git a/clc b/clc index 68864c2..8247903 100755 --- a/clc +++ b/clc @@ -1,130 +1,63 @@ #!/usr/bin/env bash -clc () -{ - if [ $# -eq 0 ]; then - clc_parse; - else - case "${1}" in - -v | --version) - echo 'v1.1.1' - ;; - -e | --escape) - shift; - clc "$@" | sed -E 's,(\x1B\[[0-9;]*[a-zA-Z]),\\\[\1\\\],g' - ;; - *) - printf '%s' "$@" | clc - ;; - esac; - fi -} -clc_code_bg () -{ - local fg="$(clc_code_"${@}")"; - echo "4${fg:1}" -} -clc_code_black () -{ - echo 30 -} -clc_code_blink () -{ - echo 5 -} -clc_code_blue () -{ - echo 34 -} -clc_code_bold () -{ - echo 1 -} -clc_code_cyan () -{ - echo 36 -} -clc_code_dim () -{ - echo 2 -} -clc_code_green () -{ - echo 32 -} -clc_code_invisible () -{ - echo 8 -} -clc_code_italic () -{ - echo 3 -} -clc_code_magenta () -{ - echo 35 -} -clc_code_normal () -{ - echo 0 -} -clc_code_red () -{ - echo 31 -} -clc_code_reverse () -{ - echo 7 -} -clc_code_rgb () -{ - echo "38;2;${1};${2};${3}" -} -clc_code_strike () -{ - echo 9 -} -clc_code_underline () -{ - echo 4 -} -clc_code_white () -{ - echo 37 -} -clc_code_yellow () -{ - echo 33 -} -clc_parse () -{ - ( while IFS= read -n 1 -d '' char; do - case "${char}" in - '>') - printf '\e[0m'; - return 0 - ;; - '<') - raw_code=$(clc_parse_directive); - printf '\e[%bm' "${raw_code}"; - clc_parse "$@" "${raw_code}"; - printf '\e[%bm' "$@" - ;; - *) - printf '%b' "${char}" - ;; - esac; - done ) + +clc() { + if [ $# -eq 0 ]; then + clc_parse + else + case "${1}" in + -v|--version) echo 'v1.1.2';; + -e|--escape) shift; clc "$@" | sed -E 's,(\x1B\[[0-9;]*[a-zA-Z]),\\\[\1\\\],g';; + *) printf '%s' "$@" | clc + esac + fi } -clc_parse_directive () -{ - ( IFS= read -r -d ':' directives; - IFS=+; - for directive in ${directives}; - do - eval "clc_code_$(printf ${directive} | xargs)"; - done | paste -sd ';' - ) + +clc_parse() ( + while IFS= read -n 1 -d '' char; do + case "${char}" in + '>') printf '\e[0m'; return 0;; + '<') raw_code=$(clc_parse_directive) + printf '\e[%bm' "${raw_code}" + clc_parse "$@" "${raw_code}" + printf '\e[%bm' "$@";; + *) printf '%b' "${char}";; + esac + done +) + +clc_parse_directive() ( + IFS= read -r -d ':' directives; + IFS=+ + for directive in ${directives}; do + eval "clc_code_$(printf ${directive} | xargs)" + done | paste -sd ';' - +) + +clc_code_black() { echo 30; } +clc_code_red() { echo 31; } +clc_code_green() { echo 32; } +clc_code_yellow() { echo 33; } +clc_code_blue() { echo 34; } +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_bg() { + local fg="$(clc_code_"${@}")" + echo "4${fg:1}" } +clc_code_normal() { echo 0; } +clc_code_bold() { echo 1; } +clc_code_dim() { echo 2; } +clc_code_italic() { echo 3; } +clc_code_underline() { echo 4; } +clc_code_blink() { echo 5; } +clc_code_reverse() { echo 7; } +clc_code_invisible() { echo 8; } +clc_code_strike() { echo 9; } + # run `clc` if not being sorced # https://stackoverflow.com/a/2684300 if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then diff --git a/make_bundle b/make_bundle deleted file mode 100755 index f62e217..0000000 --- a/make_bundle +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -echo '#!/usr/bin/env bash' - -eval "$(printf 'source "%s"\n' "$@")" - -declare -f # print the imported functions - -printf ' -# run `clc` if not being sorced -# https://stackoverflow.com/a/2684300 -if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then - clc "${@}" -fi -' diff --git a/src/clc.bash b/src/clc.bash deleted file mode 100644 index 2c683fd..0000000 --- a/src/clc.bash +++ /dev/null @@ -1,32 +0,0 @@ -clc() { - if [ $# -eq 0 ]; then - clc_parse - else - case "${1}" in - -v|--version) echo 'v1.1.1';; - -e|--escape) shift; clc "$@" | sed -E 's,(\x1B\[[0-9;]*[a-zA-Z]),\\\[\1\\\],g';; - *) printf '%s' "$@" | clc - esac - fi -} - -clc_parse() ( - while IFS= read -n 1 -d '' char; do - case "${char}" in - '>') printf '\e[0m'; return 0;; - '<') raw_code=$(clc_parse_directive) - printf '\e[%bm' "${raw_code}" - clc_parse "$@" "${raw_code}" - printf '\e[%bm' "$@";; - *) printf '%b' "${char}";; - esac - done -) - -clc_parse_directive() ( - IFS= read -r -d ':' directives; - IFS=+ - for directive in ${directives}; do - eval "clc_code_$(printf ${directive} | xargs)" - done | paste -sd ';' - -) diff --git a/src/clc_code.bash b/src/clc_code.bash deleted file mode 100644 index 23c6ca1..0000000 --- a/src/clc_code.bash +++ /dev/null @@ -1,31 +0,0 @@ -clc_code_rgb() { - echo "38;2;${1};${2};${3}"; -} - -clc_code_bg() { - local fg="$(clc_code_"${@}")" - echo "4${fg:1}" -} - -__clc_short_hands() { - local key - local -A lookup_attr=( - [normal]='0' [bold]='1' [dim]='2' [italic]='3' [underline]='4' - [blink]='5' [reverse]='7' [invisible]='8' [strike]='9' - ) - local -A lookup_color=( - [black]='0' [red]='1' [green]='2' [yellow]='3' - [blue]='4' [magenta]='5' [cyan]='6' [white]='7' - ) - - for key in "${!lookup_attr[@]}"; do - eval "clc_code_${key}(){ echo "${lookup_attr[${key}]}"; }" - done - - for key in "${!lookup_color[@]}"; do - eval "clc_code_${key}(){ echo "3${lookup_color[${key}]}"; }" - done -} - -__clc_short_hands -unset __clc_short_hands diff --git a/test_example.bash b/test_example.bash deleted file mode 100644 index 1a112f7..0000000 --- a/test_example.bash +++ /dev/null @@ -1,17 +0,0 @@ -source './clc' - -clc '\ -,\ - \ - > -' - -PS1=$(clc --escape '\ -\ -\ - \ -\ -]>$ >')