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

Add typeasserts to convert(::Type{Face}, ::Dict) #98

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/faces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -664,55 +664,57 @@ Load all faces declared in the Faces.toml file `tomlfile`.
"""
loaduserfaces!(tomlfile::String) = loaduserfaces!(Base.parsed_toml(tomlfile))

function Base.convert(::Type{Face}, spec::Dict)
function Base.convert(::Type{Face}, spec::Dict{String,Any})
Face(if haskey(spec, "font") && spec["font"] isa String
spec["font"] end,
spec["font"]::String
end,
if haskey(spec, "height") && (spec["height"] isa Int || spec["height"] isa Float64)
spec["height"]
spec["height"]::Union{Int,Float64}
end,
if haskey(spec, "weight") && spec["weight"] isa String
Symbol(spec["weight"])
Symbol(spec["weight"]::String)
elseif haskey(spec, "bold") && spec["bold"] isa Bool
ifelse(spec["bold"], :bold, :normal)
ifelse(spec["bold"]::Bool, :bold, :normal)
end,
if haskey(spec, "slant") && spec["slant"] isa String
Symbol(spec["slant"])
Symbol(spec["slant"]::String)
elseif haskey(spec, "italic") && spec["italic"] isa Bool
ifelse(spec["italic"], :italic, :normal)
ifelse(spec["italic"]::Bool, :italic, :normal)
end,
if haskey(spec, "foreground") && spec["foreground"] isa String
tryparse(SimpleColor, spec["foreground"])
tryparse(SimpleColor, spec["foreground"]::String)
elseif haskey(spec, "fg") && spec["fg"] isa String
tryparse(SimpleColor, spec["fg"])
tryparse(SimpleColor, spec["fg"]::String)
end,
if haskey(spec, "background") && spec["background"] isa String
tryparse(SimpleColor, spec["background"])
tryparse(SimpleColor, spec["background"]::String)
elseif haskey(spec, "bg") && spec["bg"] isa String
tryparse(SimpleColor, spec["bg"])
tryparse(SimpleColor, spec["bg"]::String)
end,
if !haskey(spec, "underline")
elseif spec["underline"] isa Bool
spec["underline"]
spec["underline"]::Bool
elseif spec["underline"] isa String
tryparse(SimpleColor, spec["underline"])
elseif spec["underline"] isa Vector && length(spec["underline"]) == 2
color = tryparse(SimpleColor, spec["underline"][1])
(color, Symbol(spec["underline"][2]))
tryparse(SimpleColor, spec["underline"]::String)
elseif spec["underline"] isa Vector{String} && length(spec["underline"]::Vector{String}) == 2
color_str, style_str = (spec["underline"]::Vector{String})
color = tryparse(SimpleColor, color_str)
(color, Symbol(style_str))
end,
if !haskey(spec, "strikethrough")
elseif spec["strikethrough"] isa Bool
spec["strikethrough"]
spec["strikethrough"]::Bool
elseif spec["strikethrough"] isa String
tryparse(SimpleColor, spec["strikethrough"])
tryparse(SimpleColor, spec["strikethrough"]::String)
end,
if haskey(spec, "inverse") && spec["inverse"] isa Bool
spec["inverse"] end,
spec["inverse"]::Bool end,
if !haskey(spec, "inherit")
Symbol[]
elseif spec["inherit"] isa String
[Symbol(spec["inherit"])]
[Symbol(spec["inherit"]::String)]
elseif spec["inherit"] isa Vector{String}
Symbol.(spec["inherit"])
Symbol.(spec["inherit"]::Vector{String})
else
Symbol[]
end)
Expand Down
Loading