module Ermine.Version
( logo
, version
) where
import Control.Applicative
import Data.ByteString.UTF8 (toString)
import Data.FileEmbed
import Data.List.Split
import Data.Version
import qualified Paths_ermine
import System.FilePath
import System.Random
import System.IO.Unsafe
logo :: String
logo = unsafePerformIO $ randomRIO (0,29 :: Int) >>= \n -> if n == 0 then logos else return rat
version :: String
version = showVersion Paths_ermine.version { versionTags = ["α"] }
logos :: IO String
logos = do
let txt = filter ((>3).length)
. splitOn [""] . lines . toString $ $(embedFile $ "etc" </> "logos.txt")
small:xs@(l1:l2:l3:l4:rest) <- (txt !!) <$> randomRIO (0, length txt 1)
let n = maximum (map length xs)
let pad ys = ys ++ replicate (n length ys) ' '
(nm, slogan) = drop 1 <$> break (';'==) small
return $ unlines $
[ l1
, pad l2 ++ ' ' : nm ++ ' ' : version
, l3
, pad l4 ++ ' ' : slogan
] ++ rest
rat :: String
rat = toString $ $(embedFile $ "etc" </> "logo.txt")