Thanks for the quick answer, it helps!
Albeit a bit too nitty gritty for me, will make a post and see if others have found a good solution
Kind regards
Thanks for the quick answer, it helps!
Albeit a bit too nitty gritty for me, will make a post and see if others have found a good solution
Kind regards
This package looks great!
One comment I have is that macros are used unnecessarily. The string style functions like @red
, @bold
or @underline
don’t do anything that a function couldn’t do, and should really just be exposed to the user as normal functions.
I.e., define
function red(txt)
code = ANSICode(get_color("red"); bg = false)
styled = apply_style(txt)
code.open * styled * code.close
end
instead of
macro red(text)
quote
local txt = $(esc(text))
code = ANSICode(get_color("red"); bg = false)
styled = apply_style(txt)
string(code.open * styled * code.close)
end
end
as in macros.jl
.
I agree that a little syntactic sugar would be nice, though. I propose something like
julia> macro red_str(txt)
code = ANSICode(get_color("red"); bg = false)
code.open*apply_style(string(txt))*code.close
end
@red_str (macro with 1 method)
julia> red"apple"
"\e[31mapple\e[39m"
Another neat available (but less readable) syntax might be:
julia> const style_flags = Dict('r' => "red", 'u' => "underline");
julia> macro c_str(txt, flags)
styles = [getindex(style_flags, flag) for flag in flags]
println("applying styles: ", styles)
txt
end
@c_str (macro with 1 method)
julia> c"hello"ru
applying styles: ["red", "underline"]
"hello"
hey thanks!
That’s a fair point.
However I don’t see much of a change between using @red
and @red_str
and making this change would break existing code for users that have been using the macros as they are. Given that it would be just a small syntactic change I don’t think it makes it worth it to have this breaking change.
Thanks for the input though, get in touch if you have more ideas/requests!
Keep me posted!