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

apply_style function doesn't work for AbstractString type #233

Open
fdekerme opened this issue Aug 8, 2023 · 0 comments
Open

apply_style function doesn't work for AbstractString type #233

fdekerme opened this issue Aug 8, 2023 · 0 comments

Comments

@fdekerme
Copy link

fdekerme commented Aug 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant