mirror of
https://github.com/CrystalSplitter/ghcitui.git
synced 2024-10-26 19:11:28 +03:00
24 lines
600 B
Haskell
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
|