KristofferC / Crayons.jl

Colored and styled strings for terminals.
Other
150 stars 14 forks source link

Syntactic sugar for binary pairs #38

Closed caseykneale closed 4 years ago

caseykneale commented 4 years ago

I really like crayons but it adds a bit of bloat syntactically. Would it be reasonable to suggest something like the following below?

using Crayons
cols = "black, red, green, yellow, blue, magenta, cyan, light_gray, default, dark_gray, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan, white"
fxs = "reset, bold, faint, italics, underline, blink, negative, conceal, strikethrough"

for (col, fx) in Iterators.product( split(cols, ", "), split(fxs, ", ") )
    name = Symbol(col * "_" * fx)
    global colsym = Symbol( col )
    global fxsym = Symbol( fx )
    @eval $colsym = colsym
    @eval $fxsym = fxsym
    @eval $name() = Crayon( foreground = $colsym, $fxsym = true)
end

print( magenta_italics(), "woah", cyan_underline(), " wooooo" )

Basically just make it a little less verbose so you don't end up with really long lines of code to print text?

KristofferC commented 4 years ago

There are some hardcoded combinations in https://github.com/KristofferC/Crayons.jl/issues/38.

You can also use the string macro

bild

caseykneale commented 4 years ago

Did I reinvent something already existing? if so just close this "issue".