Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Color Support #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 24 additions & 3 deletions JSON.sh
@@ -1,3 +1,24 @@
if isatty && [ ! -z "$(which isatty)" ];then
TXT_BLD=$(tput bold)
TXT_RED=$(tput setaf 1)
TXT_GREEN=$(tput setaf 2)
TXT_YLW=$(tput setaf 3)
TXT_BLUE=$(tput setaf 4)
TXT_PURPLE=$(tput setaf 5)
TXT_CYAN=$(tput setaf 6)
TXT_WHITE=$(tput setaf 7)
TXT_RESET=$(tput sgr0)
else
TXT_BLD=
TXT_RED=
TXT_GREEN=
TXT_YLW=
TXT_BLUE=
TXT_PURPLE=
TXT_CYAN=
TXT_WHITE=
TXT_RESET=
fi

throw () {
echo "$*" >&2
Expand Down Expand Up @@ -26,7 +47,7 @@ parse_array () {
do
parse_value "$1" "$index"
let index=$index+1
ary="$ary""$value"
ary="$ary""$value"
read -r token
case "$token" in
']') break ;;
Expand Down Expand Up @@ -60,7 +81,7 @@ parse_object () {
esac
read -r token
parse_value "$1" "$key"
obj="$obj$key:$value"
obj="$obj$TXT_BLUE$key$TXT_RESET:$TXT_RED$value$TXT_RESET"
read -r token
case "$token" in
'}') break ;;
Expand All @@ -83,7 +104,7 @@ parse_value () {
''|[^0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token ;;
esac
printf "[%s]\t%s\n" "$jpath" "$value"
printf "[%s]\t%s\n" "$TXT_GREEN$jpath$TXT_RESET" "$TXT_PURPLE$value$TXT_RESET"
}

parse () {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -6,10 +6,10 @@
{ "type": "git"
, "url": "https://github.com/dominictarr/JSON-sh.git" }
, "bin": {
"json_parse": "./JSON.sh"
"json_parse": "./JSON.sh",
"JSON.sh": "./JSON.sh"
}
, "dependencies": {}
, "devDependencies": {}
, "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://bit.ly/dominictarr)"
, "scripts": { "test": "./all-tests.sh" } }
, "scripts": { "test": "./all-tests.sh" } }