summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/Layout.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 03:37:15 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 03:37:15 +0400
commited25a297094b483dce06e14d52ced2f93f6dca41 (patch)
tree3df60d8b30af29345de021f251903a175e78c70c /src/Data/Torrent/Layout.hs
parent708938679954a5d5f9def82e1fa873c19ed662df (diff)
Use pretty-class package
Diffstat (limited to 'src/Data/Torrent/Layout.hs')
-rw-r--r--src/Data/Torrent/Layout.hs17
1 files changed, 7 insertions, 10 deletions
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
24 24
25 -- * Single file info 25 -- * Single file info
26 , FileInfo (..) 26 , FileInfo (..)
27 , ppFileInfo
28 27
29 -- ** Lens 28 -- ** Lens
30 , fileLength 29 , fileLength
@@ -33,7 +32,6 @@ module Data.Torrent.Layout
33 32
34 -- * File layout 33 -- * File layout
35 , LayoutInfo (..) 34 , LayoutInfo (..)
36 , ppLayoutInfo
37 , joinFilePath 35 , joinFilePath
38 36
39 -- ** Lens 37 -- ** Lens
@@ -78,6 +76,7 @@ import Data.Text as T
78import Data.Text.Encoding as T 76import Data.Text.Encoding as T
79import Data.Typeable 77import Data.Typeable
80import Text.PrettyPrint as PP 78import Text.PrettyPrint as PP
79import Text.PrettyPrint.Class
81import System.FilePath 80import System.FilePath
82import System.Posix.Types 81import System.Posix.Types
83 82
@@ -175,13 +174,12 @@ instance BEncode (FileInfo ByteString) where
175 fromBEncode = fromDict getFileInfoSingle 174 fromBEncode = fromDict getFileInfoSingle
176 {-# INLINE fromBEncode #-} 175 {-# INLINE fromBEncode #-}
177 176
178-- | Format 'FileInfo' in human-readable form. 177instance Pretty (FileInfo BS.ByteString) where
179ppFileInfo :: FileInfo ByteString -> Doc 178 pretty FileInfo {..} =
180ppFileInfo FileInfo {..} =
181 "Path: " <> text (T.unpack (T.decodeUtf8 fiName)) 179 "Path: " <> text (T.unpack (T.decodeUtf8 fiName))
182 $$ "Size: " <> text (show fiLength) 180 $$ "Size: " <> text (show fiLength)
183 $$ maybe PP.empty ppMD5 fiMD5Sum 181 $$ maybe PP.empty ppMD5 fiMD5Sum
184 where 182 where
185 ppMD5 md5 = "MD5 : " <> text (show (InfoHash md5)) 183 ppMD5 md5 = "MD5 : " <> text (show (InfoHash md5))
186 184
187-- | Join file path. 185-- | Join file path.
@@ -242,10 +240,9 @@ instance BEncode LayoutInfo where
242 toBEncode = toDict . (`putLayoutInfo` endDict) 240 toBEncode = toDict . (`putLayoutInfo` endDict)
243 fromBEncode = fromDict getLayoutInfo 241 fromBEncode = fromDict getLayoutInfo
244 242
245-- | Format 'LayoutInfo' in human readable form. 243instance Pretty LayoutInfo where
246ppLayoutInfo :: LayoutInfo -> Doc 244 pretty SingleFile {..} = pretty liFile
247ppLayoutInfo SingleFile {..} = ppFileInfo liFile 245 pretty MultiFile {..} = vcat $ L.map (pretty . joinFilePath) liFiles
248ppLayoutInfo MultiFile {..} = vcat $ L.map (ppFileInfo . joinFilePath) liFiles
249 246
250-- | Test if this is single file torrent. 247-- | Test if this is single file torrent.
251isSingleFile :: LayoutInfo -> Bool 248isSingleFile :: LayoutInfo -> Bool