ghcitui/app/Util.hs
2023-08-30 00:45:59 -07:00

24 lines
600 B
Haskell

module Util where
import Data.Text (Text, pack)
showT :: (Show a) => a -> Text
showT = Data.Text.pack . show
-- Return the number of digits in a given integral
getNumDigits :: (Integral a) => a -> Int
getNumDigits 0 = 1
getNumDigits num = truncate (logBase 10 (fromIntegral num) :: Double) + 1
-- | Format digits into a string with padding.
formatDigits
:: Int
-- ^ Number of spaces
-> Int
-- ^ Number to format digits of
-> Text
-- ^ Formatted Text
formatDigits spacing num = pack (replicate amount ' ') <> pack (show num)
where
amount = spacing - getNumDigits num