module Quarry where import Text.Printf import System.Console.ANSI import Control.Monad(forM_) data RetriveData = MagnetLinkURL { magnetLink :: String, magnetHash :: String } deriving (Show) data Quarry = Quarry { seed :: Int, leech :: Int, retrive :: RetriveData, uploaded :: String, size :: String, files :: Int, meta :: String, title :: String } instance Show Quarry where show q = printf "%-30s (%d/%d) uploaded %s" (take 30 $ title q) (seed q) (leech q) (uploaded q) class Show a => TerminalOutput a where termOutput :: a -> IO () instance TerminalOutput Quarry where termOutput q = do setSGR [SetColor Foreground Vivid Magenta, SetConsoleIntensity BoldIntensity] printf " %-50s " $ take 50 (title q) :: IO () setSGR [Reset, SetConsoleIntensity BoldIntensity] >> printf " %s " (uploaded q) :: IO () setSGR [] >> printf " [" :: IO () setSGR [SetColor Foreground Vivid Green] >> printf "%d" (seed q) :: IO () setSGR [] >> printf "/" ::IO () setSGR [SetColor Foreground Dull Red] >> printf "%d" (leech q) :: IO () setSGR [] >> printf "]" :: IO () setSGR [] >> printf "\n" :: IO () instance TerminalOutput [Quarry] where termOutput list = forM_ (zip list [1..]) outputLine where outputLine :: (Quarry, Int) -> IO () outputLine (q, n) = do setSGR [SetConsoleIntensity BoldIntensity, SetColor Foreground Dull Cyan] printf "%-3d" n :: IO () termOutput q