Term.jl icon indicating copy to clipboard operation
Term.jl copied to clipboard

apply_style function doesn't work for AbstractString type

Open fdekerme opened this issue 1 year ago • 0 comments

Hello, would it be possible to extend the apply_style function to SubString type (and AbstractString in general)?

Example :

julia> using Term.Trees

julia> ss = SubString("abc", 1:2)
"ab"

julia> typeof(ss)
SubString{String}

julia> d = Dict("1" => "abd", "2" => ss)
Dict{String, AbstractString} with 2 entries:
  "1" => "abd"
  "2" => "ab"

julia> Tree(d)
ERROR: MethodError: no method matching apply_style(::SubString{String}, ::String)

Closest candidates are:
  apply_style(::String, ::String)
   @ Term C:\Users\franc\.julia\packages\Term\z1tSn\src\style.jl:22
  apply_style(::Any; leave_orphan_tags)
   @ Term C:\Users\franc\.julia\packages\Term\z1tSn\src\style.jl:142

I simply suggest to dispatch the function :

function apply_style(text::AbstractString, style::String)
    text = convert(String, text)
    apply_style(text, style)
end

Thanks ! fderkem

fdekerme avatar Aug 08 '23 09:08 fdekerme