Skip to content

Commit 507ef21

Browse files
oxinaboxKristofferC
authored andcommitted
Allow AbstractStrings (#22)
* Allow AbstractStrings * test substrings * Update crayon_wrapper.jl
1 parent f17f76c commit 507ef21

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/crayon_wrapper.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ struct CrayonWrapper
33
v::Vector{Union{CrayonWrapper,String}}
44
end
55

6-
function (c::Crayon)(args::Union{CrayonWrapper,String}...)
7-
CrayonWrapper(c, collect(args))
6+
function (c::Crayon)(args::Union{CrayonWrapper,AbstractString}...)
7+
typefix(cw::CrayonWrapper) = cw
8+
typefix(str) = String(str)
9+
10+
CrayonWrapper(c, typefix.(collect(args)))
811
end
912

1013
Base.show(io::IO, cw::CrayonWrapper) = _show(io, cw, CrayonStack(incremental = true))

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ print_with_color(Crayon(foreground = :red), io, "haho")
133133

134134
# Call overloading
135135
@test string(Crayon()("hello")) == "hello"
136+
@test string(Crayon()(split("hello world")[1])) == "hello" # test substrings
136137
@test string(Crayon(bold=true)("hello")) == string(BOLD, "hello", inv(BOLD))
137138
@test string(Crayon(bold=true, foreground = :red)("hello")) == string(Crayon(foreground=:red, bold=true), "hello", Crayon(foreground=:default, bold=false))
138139

0 commit comments

Comments
 (0)