ENH use disgusting hack to simulate a sum type in yaml

This commit is contained in:
Nathan Dwarshuis 2022-08-11 23:03:33 -04:00
parent 40678a8e17
commit 53544b347e
2 changed files with 59 additions and 59 deletions

View File

@ -153,65 +153,74 @@ let Pattern =
| GradientRGBA : List StopRGBA | GradientRGBA : List StopRGBA
> >
let Annotated = \(a : Type) -> { type : Text, data : a }
let annotate =
\(a : Pattern) ->
{ type = showConstructor a, data = a } : Annotated Pattern
let APattern = Annotated Pattern
let symGradient =
\(c0 : Natural) ->
\(c1 : Natural) ->
annotate
( Pattern.GradientRGB
[ { color = c0, stop = 0.0 }
, { color = c1, stop = 0.5 }
, { color = c0, stop = 1.0 }
]
)
let Patterns = let Patterns =
{ Type = { Type =
{ header : Pattern { header : APattern
, panel : { bg : Pattern } , panel : { bg : APattern }
, text : { active : Pattern, inactive : Pattern, critical : Pattern } , text :
, border : Pattern { active : APattern, inactive : APattern, critical : APattern }
, border : APattern
, plot : , plot :
{ grid : Pattern { grid : APattern
, outline : Pattern , outline : APattern
, data : { border : Pattern, fill : Pattern } , data : { border : APattern, fill : APattern }
} }
, indicator : , indicator :
{ bg : Pattern, fg : { active : Pattern, critical : Pattern } } { bg : APattern, fg : { active : APattern, critical : APattern } }
} }
, default = , default =
{ header = Pattern.RGB 0xefefef { header = annotate (Pattern.RGB 0xefefef)
, panel.bg = Pattern.RGBA { color = 0x121212, alpha = 0.7 } , panel.bg = annotate (Pattern.RGBA { color = 0x121212, alpha = 0.7 })
, text = , text =
{ active = Pattern.RGB 0xbfe1ff { active = annotate (Pattern.RGB 0xbfe1ff)
, inactive = Pattern.RGB 0xc8c8c8 , inactive = annotate (Pattern.RGB 0xc8c8c8)
, critical = Pattern.RGB 0xff8282 , critical = annotate (Pattern.RGB 0xff8282)
} }
, border = Pattern.RGB 0x888888 , border = annotate (Pattern.RGB 0x888888)
, plot = , plot =
{ grid = Pattern.RGB 0x666666 { grid = annotate (Pattern.RGB 0x666666)
, outline = Pattern.RGB 0x777777 , outline = annotate (Pattern.RGB 0x777777)
, data = , data =
{ border = { border =
Pattern.GradientRGB annotate
[ { color = 0x003f7c, stop = 0.0 } ( Pattern.GradientRGB
, { color = 0x1e90ff, stop = 1.0 } [ { color = 0x003f7c, stop = 0.0 }
] , { color = 0x1e90ff, stop = 1.0 }
]
)
, fill = , fill =
Pattern.GradientRGBA annotate
[ { color = 0x316ece, stop = 0.2, alpha = 0.5 } ( Pattern.GradientRGBA
, { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 } [ { color = 0x316ece, stop = 0.2, alpha = 0.5 }
] , { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 }
]
)
} }
} }
, indicator = , indicator =
{ bg = { bg = symGradient 0x565656 0xbfbfbf
Pattern.GradientRGB
[ { color = 0x565656, stop = 0.0 }
, { color = 0xbfbfbf, stop = 0.5 }
, { color = 0x565656, stop = 1.0 }
]
, fg = , fg =
{ active = { active = symGradient 0x316BA6 0x99CEFF
Pattern.GradientRGB , critical = symGradient 0xFF3333 0xFFB8B8
[ { color = 0x316BA6, stop = 0.0 }
, { color = 0x99CEFF, stop = 0.5 }
, { color = 0x316BA6, stop = 1.0 }
]
, critical =
Pattern.GradientRGB
[ { color = 0xFF3333, stop = 0.0 }
, { color = 0xFFB8B8, stop = 0.5 }
, { color = 0xFF3333, stop = 1.0 }
]
} }
} }
} }

View File

@ -61,23 +61,14 @@ local compile_patterns
compile_patterns = function(patterns) compile_patterns = function(patterns)
local r = {} local r = {}
for k, v in pairs(patterns) do for k, v in pairs(patterns) do
-- number -> solid color if v.type == "RGB" then
if type(v) == "number" then r[k] = rgb(v.data)
r[k] = rgb(v) elseif v.type == "RGBA" then
-- { color = x, alpha = y} -> alpha color r[k] = rgba(v.data.color, v.data.alpha)
elseif v.color ~= nil then elseif v.type == "GradientRGB" then
r[k] = rgba(v.color, v.alpha) r[k] = compile_gradient(v.data)
-- ASSUME non-empty array is a gradient elseif v.type == "GradientRGBA" then
elseif #v > 0 then r[k] = compile_gradient_alpha(v.data)
-- ASSUME alpha gradient will have color/stop/alpha records for each
-- member, so just check the first
if v[1].alpha ~= nil then
r[k] = compile_gradient_alpha(v)
else
r[k] = compile_gradient(v)
end
-- ASSUME nothing else in the tree is a number, a table with 'color', or
-- an array
else else
r[k] = compile_patterns(v) r[k] = compile_patterns(v)
end end