Skip to content

Commit 729f56c

Browse files
topolaritytecosaur
authored andcommitted
Add typeasserts to convert(::Type{Face}, ::Dict)
This removes a ton of implicit converts from this code, which are easily invalidated.
1 parent 056e843 commit 729f56c

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/faces.jl

+23-21
Original file line numberDiff line numberDiff line change
@@ -664,55 +664,57 @@ Load all faces declared in the Faces.toml file `tomlfile`.
664664
"""
665665
loaduserfaces!(tomlfile::String) = loaduserfaces!(Base.parsed_toml(tomlfile))
666666

667-
function Base.convert(::Type{Face}, spec::Dict)
667+
function Base.convert(::Type{Face}, spec::Dict{String,Any})
668668
Face(if haskey(spec, "font") && spec["font"] isa String
669-
spec["font"] end,
669+
spec["font"]::String
670+
end,
670671
if haskey(spec, "height") && (spec["height"] isa Int || spec["height"] isa Float64)
671-
spec["height"]
672+
spec["height"]::Union{Int,Float64}
672673
end,
673674
if haskey(spec, "weight") && spec["weight"] isa String
674-
Symbol(spec["weight"])
675+
Symbol(spec["weight"]::String)
675676
elseif haskey(spec, "bold") && spec["bold"] isa Bool
676-
ifelse(spec["bold"], :bold, :normal)
677+
ifelse(spec["bold"]::Bool, :bold, :normal)
677678
end,
678679
if haskey(spec, "slant") && spec["slant"] isa String
679-
Symbol(spec["slant"])
680+
Symbol(spec["slant"]::String)
680681
elseif haskey(spec, "italic") && spec["italic"] isa Bool
681-
ifelse(spec["italic"], :italic, :normal)
682+
ifelse(spec["italic"]::Bool, :italic, :normal)
682683
end,
683684
if haskey(spec, "foreground") && spec["foreground"] isa String
684-
tryparse(SimpleColor, spec["foreground"])
685+
tryparse(SimpleColor, spec["foreground"]::String)
685686
elseif haskey(spec, "fg") && spec["fg"] isa String
686-
tryparse(SimpleColor, spec["fg"])
687+
tryparse(SimpleColor, spec["fg"]::String)
687688
end,
688689
if haskey(spec, "background") && spec["background"] isa String
689-
tryparse(SimpleColor, spec["background"])
690+
tryparse(SimpleColor, spec["background"]::String)
690691
elseif haskey(spec, "bg") && spec["bg"] isa String
691-
tryparse(SimpleColor, spec["bg"])
692+
tryparse(SimpleColor, spec["bg"]::String)
692693
end,
693694
if !haskey(spec, "underline")
694695
elseif spec["underline"] isa Bool
695-
spec["underline"]
696+
spec["underline"]::Bool
696697
elseif spec["underline"] isa String
697-
tryparse(SimpleColor, spec["underline"])
698-
elseif spec["underline"] isa Vector && length(spec["underline"]) == 2
699-
color = tryparse(SimpleColor, spec["underline"][1])
700-
(color, Symbol(spec["underline"][2]))
698+
tryparse(SimpleColor, spec["underline"]::String)
699+
elseif spec["underline"] isa Vector{String} && length(spec["underline"]::Vector{String}) == 2
700+
color_str, style_str = (spec["underline"]::Vector{String})
701+
color = tryparse(SimpleColor, color_str)
702+
(color, Symbol(style_str))
701703
end,
702704
if !haskey(spec, "strikethrough")
703705
elseif spec["strikethrough"] isa Bool
704-
spec["strikethrough"]
706+
spec["strikethrough"]::Bool
705707
elseif spec["strikethrough"] isa String
706-
tryparse(SimpleColor, spec["strikethrough"])
708+
tryparse(SimpleColor, spec["strikethrough"]::String)
707709
end,
708710
if haskey(spec, "inverse") && spec["inverse"] isa Bool
709-
spec["inverse"] end,
711+
spec["inverse"]::Bool end,
710712
if !haskey(spec, "inherit")
711713
Symbol[]
712714
elseif spec["inherit"] isa String
713-
[Symbol(spec["inherit"])]
715+
[Symbol(spec["inherit"]::String)]
714716
elseif spec["inherit"] isa Vector{String}
715-
Symbol.(spec["inherit"])
717+
Symbol.(spec["inherit"]::Vector{String})
716718
else
717719
Symbol[]
718720
end)

0 commit comments

Comments
 (0)