From 4b43e63a89ff2def0cb70b9dd8af23e11b689c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gr=C3=BCnewald?= Date: Sat, 18 Feb 2023 13:00:11 +0100 Subject: [PATCH] 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. --- hledger/Hledger/Cli/Commands.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index c11c2d0bc..3e7710f97 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -277,7 +277,7 @@ multicol _ [] = [] multicol width strs = let maxwidth = maximum' $ map length strs - numcols = width `div` (maxwidth+2) + numcols = min (length strs) (width `div` (maxwidth+2)) itemspercol = length strs `div` numcols colitems = chunksOf itemspercol strs cols = map unlines colitems