fix: cli: don't crash multicol with few strings

When there are only few, short strs and width is large, then the div
operation in itemspercol would return zero, triggering and error in
chunksOf.

This fix makes numcols have always at least as many entries as strs,
filling one line.
This commit is contained in:
Michael Grünewald 2023-02-18 13:00:11 +01:00 committed by Simon Michael
parent fa70f160ae
commit 4b43e63a89

View File

@ -277,7 +277,7 @@ multicol _ [] = []
multicol width strs = multicol width strs =
let let
maxwidth = maximum' $ map length strs maxwidth = maximum' $ map length strs
numcols = width `div` (maxwidth+2) numcols = min (length strs) (width `div` (maxwidth+2))
itemspercol = length strs `div` numcols itemspercol = length strs `div` numcols
colitems = chunksOf itemspercol strs colitems = chunksOf itemspercol strs
cols = map unlines colitems cols = map unlines colitems