mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
lib: Hledger.Utils: added multicol
This commit is contained in:
parent
ae4f58beb7
commit
76f336695c
@ -47,6 +47,7 @@ module Hledger.Utils (
|
||||
sixth6,
|
||||
|
||||
-- * Misc
|
||||
multicol,
|
||||
numDigitsInt,
|
||||
makeHledgerClassyLenses,
|
||||
|
||||
@ -66,8 +67,10 @@ module Hledger.Utils (
|
||||
where
|
||||
|
||||
import Data.Char (toLower)
|
||||
import Data.List.Extra (foldl', foldl1', uncons, unsnoc)
|
||||
import Data.List (intersperse)
|
||||
import Data.List.Extra (chunksOf, foldl', foldl1', uncons, unsnoc)
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Text as T (pack, unpack)
|
||||
import Data.Tree (foldTree, Tree (Node, subForest))
|
||||
import Language.Haskell.TH (DecsQ, Name, mkName, nameBase)
|
||||
import Lens.Micro ((&), (.~))
|
||||
@ -199,6 +202,21 @@ sixth6 (_,_,_,_,_,x) = x
|
||||
|
||||
-- Misc
|
||||
|
||||
-- | Convert a list of strings to a multi-line multi-column list
|
||||
-- fitting within the given width. Not wide character aware.
|
||||
multicol :: Int -> [String] -> String
|
||||
multicol _ [] = []
|
||||
multicol width strs =
|
||||
let
|
||||
maxwidth = maximum' $ map length strs
|
||||
numcols = min (length strs) (width `div` (maxwidth+2))
|
||||
itemspercol = length strs `div` numcols
|
||||
colitems = chunksOf itemspercol strs
|
||||
cols = map unlines colitems
|
||||
sep = " "
|
||||
in
|
||||
T.unpack $ textConcatBottomPadded $ map T.pack $ intersperse sep cols
|
||||
|
||||
-- | Find the number of digits of an 'Int'.
|
||||
{-# INLINE numDigitsInt #-}
|
||||
numDigitsInt :: Integral a => Int -> a
|
||||
|
Loading…
Reference in New Issue
Block a user