Making a choice from a list in Haskell, Vty (part 4)
After part 3 in this series, which might have been the longest post I’ve ever put on this blog, follows a much short post. In fact it’s so short it’s rather silly.
In this post I’ll modify the Option type to render into multiple lines; two
in fact (it’s easy to see that it would work with more lines).
So, to start off, I add a second string to Option:
data Option = Option { optionRange::(Int, Int), optionS1::String, optionS2::String } deriving (Show) |
Next the definition for Pretty is changed to render an Option on two
lines:
instance Pretty Option where pretty (Option _ s1 s2) = string s1 <> line <> indent 2 (string s2) |
Due to the change to Option I also need to modify optionIsInRange:
optionIsInRange (Option (b, e) _ _) i = b <= i && i <= e |
Finally the options need to be modified as well:
options = ozFromListWithMod (optionSetRange 0) [Option (0, 0) ((show i) ++ " Foo") "Bar" | i <- [0..2]] |
That’s all there’s to it. Short and sweet.
[...] has come for the final installment of this series of “discussions of a refactoring”. These are the earlier installments. This is where I finally add the ability to collapse a list item. This [...]