From ed25a297094b483dce06e14d52ced2f93f6dca41 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sat, 23 Nov 2013 03:37:15 +0400 Subject: Use pretty-class package --- src/Data/Torrent/Layout.hs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/Data/Torrent/Layout.hs') diff --git a/src/Data/Torrent/Layout.hs b/src/Data/Torrent/Layout.hs index 84085a92..70908c4e 100644 --- a/src/Data/Torrent/Layout.hs +++ b/src/Data/Torrent/Layout.hs @@ -24,7 +24,6 @@ module Data.Torrent.Layout -- * Single file info , FileInfo (..) - , ppFileInfo -- ** Lens , fileLength @@ -33,7 +32,6 @@ module Data.Torrent.Layout -- * File layout , LayoutInfo (..) - , ppLayoutInfo , joinFilePath -- ** Lens @@ -78,6 +76,7 @@ import Data.Text as T import Data.Text.Encoding as T import Data.Typeable import Text.PrettyPrint as PP +import Text.PrettyPrint.Class import System.FilePath import System.Posix.Types @@ -175,13 +174,12 @@ instance BEncode (FileInfo ByteString) where fromBEncode = fromDict getFileInfoSingle {-# INLINE fromBEncode #-} --- | Format 'FileInfo' in human-readable form. -ppFileInfo :: FileInfo ByteString -> Doc -ppFileInfo FileInfo {..} = +instance Pretty (FileInfo BS.ByteString) where + pretty FileInfo {..} = "Path: " <> text (T.unpack (T.decodeUtf8 fiName)) $$ "Size: " <> text (show fiLength) $$ maybe PP.empty ppMD5 fiMD5Sum - where + where ppMD5 md5 = "MD5 : " <> text (show (InfoHash md5)) -- | Join file path. @@ -242,10 +240,9 @@ instance BEncode LayoutInfo where toBEncode = toDict . (`putLayoutInfo` endDict) fromBEncode = fromDict getLayoutInfo --- | Format 'LayoutInfo' in human readable form. -ppLayoutInfo :: LayoutInfo -> Doc -ppLayoutInfo SingleFile {..} = ppFileInfo liFile -ppLayoutInfo MultiFile {..} = vcat $ L.map (ppFileInfo . joinFilePath) liFiles +instance Pretty LayoutInfo where + pretty SingleFile {..} = pretty liFile + pretty MultiFile {..} = vcat $ L.map (pretty . joinFilePath) liFiles -- | Test if this is single file torrent. isSingleFile :: LayoutInfo -> Bool -- cgit v1.2.3