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

Color function maker #27

Closed
szepeviktor opened this issue Oct 24, 2014 · 16 comments
Closed

Color function maker #27

szepeviktor opened this issue Oct 24, 2014 · 16 comments

Comments

@szepeviktor
Copy link

# color = number of stars + ANSI escape code
declare -A COLORS=( [litegreen]='0\033[0;32m' [green]='2\033[1;32m' )

colorfuncmaker() {
    local COLOR_NAME
    local -i COLOR_STAR_NUM
    local COLOR_STARS=""
    local COLOR_CODE

    for COLOR_NAME in ${!COLORS[*]}; do
        COLOR_STAR_NUM="${COLORS[$COLOR_NAME]:0:1}"
        COLOR_CODE="${COLORS[$COLOR_NAME]:1}"

        if [ "$COLOR" == 0 ]; then
            # colored function
            eval "${COLOR_NAME}() { out \"${COLOR_CODE}\$1 \"; off; }"
        else
            # b/w function
            # generate stars
            if [ "$COLOR_STAR_NUM" -gt 0 ]; then
                printf -v COLOR_STARS '*%.0s' $(seq 1 ${COLORS[$COLOR_NAME]:0:1})
            fi
            eval "${COLOR_NAME}() { out \"${COLOR_STARS}\$1${COLOR_STARS} \"; }"
        fi
        # the common ...ln function
        eval "${COLOR_NAME}ln() { ${COLOR_NAME} \"\$1\"; outln; }"
    done
}

It makes testssl.sh smaller.

@szepeviktor
Copy link
Author

Maybe the b/w function variables shouldn't have a COLOR_ prefix.

@szepeviktor
Copy link
Author

Please consider including it.

@drwetter
Copy link
Owner

I removed the stars also from my code (ugly) that needs to be removed as well.
Then could you give me an example how that function would be called? I am
not quite sure about it.

Am 11/17/2014 09:57 PM, schrieb Viktor Szépe:

Please consider including it.


Reply to this email directly or view it on GitHub #27 (comment).

@szepeviktor
Copy link
Author

colorfuncmaker() generates functions like litegreen or green. So no modifications needed.
Look at the eval lines!

@drwetter
Copy link
Owner

@szepeviktor : Sorry for keeping this open for so long.

Would you mind doing a PR?

@szepeviktor
Copy link
Author

I am sorry. I'd like to contribute only one function.
The one above generates all these function: https://github.com/drwetter/testssl.sh/blob/master/testssl.sh#L256-L348
So your code gets shorter.

@szepeviktor
Copy link
Author

generates all these function

Should I explain what this means?

@drwetter
Copy link
Owner

Ok, no problem.

Like the idea though, so I reopened it for others to volunteer.

@szepeviktor
Copy link
Author

The PR is easy. You just delete the literally defined functions (for example pr_liteblueln) and put this one in your code.

@szepeviktor
Copy link
Author

You should also declare an array with all the colors.
declare -A COLORS=( [litegreen]='0\033[0;32m' [green]='2\033[0;32m' ) etc.

@szepeviktor
Copy link
Author

removed the stars also from my code

So start should also be removed from this function.

@drwetter
Copy link
Owner

Am 07/23/2015 um 01:50 PM schrieb Viktor Szépe:

generates all these function

Should I explain what this means?

I got it, not sure whether the generated functions are kind of global then.
I assume they are, otherwise you wouldn't have suggested it.

@szepeviktor
Copy link
Author

If they are not global, just make this function simply inline code.

@drwetter
Copy link
Owner

Thx!

drwetter added a commit that referenced this issue Aug 5, 2015
- reverting #27. Catch is the functions are being initiated at a fixed time instead of while calling. This conflicts with the --color option which is done late. Other solution?
@drwetter
Copy link
Owner

drwetter commented Aug 5, 2015

Needed to revert this.

Catch was the functions are being initiated at a fixed time instead of while calling.

Other solution needs to be found for this color_maker

@szepeviktor
Copy link
Author

OK

drwetter added a commit that referenced this issue Aug 15, 2015
- bumped up version to 2.6rc2
drwetter added a commit that referenced this issue Sep 3, 2015
- reverting #27. Catch is the functions are being initiated at a fixed time instead of while calling. This conflicts with the --color option which is done late. Other solution?
drwetter added a commit that referenced this issue Sep 3, 2015
- bumped up version to 2.6rc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants