module Text.Show.Text.GHC.Fingerprint (showbFingerprint) where
import Data.Semigroup (timesN)
import Data.Text.Lazy.Builder (Builder)
import Data.Word (Word64)
import GHC.Fingerprint.Type (Fingerprint(..))
import Prelude hiding (Show)
import Text.Show.Text.Classes (Show(showb))
import Text.Show.Text.Data.Integral (showbHex)
import Text.Show.Text.Utils ((<>), lengthB, s)
showbFingerprint :: Fingerprint -> Builder
showbFingerprint (Fingerprint w1 w2) = hex16 w1 <> hex16 w2
where
hex16 :: Word64 -> Builder
hex16 i = let hex = showbHex i
in timesN (fromIntegral . max 0 $ 16 lengthB hex) (s '0') <> hex
instance Show Fingerprint where
showb = showbFingerprint