diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 03:37:15 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 03:37:15 +0400 |
commit | ed25a297094b483dce06e14d52ced2f93f6dca41 (patch) | |
tree | 3df60d8b30af29345de021f251903a175e78c70c /src/Data/Torrent/Layout.hs | |
parent | 708938679954a5d5f9def82e1fa873c19ed662df (diff) |
Use pretty-class package
Diffstat (limited to 'src/Data/Torrent/Layout.hs')
-rw-r--r-- | src/Data/Torrent/Layout.hs | 17 |
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 | |||
78 | import Data.Text.Encoding as T | 76 | import Data.Text.Encoding as T |
79 | import Data.Typeable | 77 | import Data.Typeable |
80 | import Text.PrettyPrint as PP | 78 | import Text.PrettyPrint as PP |
79 | import Text.PrettyPrint.Class | ||
81 | import System.FilePath | 80 | import System.FilePath |
82 | import System.Posix.Types | 81 | import 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. | 177 | instance Pretty (FileInfo BS.ByteString) where |
179 | ppFileInfo :: FileInfo ByteString -> Doc | 178 | pretty FileInfo {..} = |
180 | ppFileInfo 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. | 243 | instance Pretty LayoutInfo where |
246 | ppLayoutInfo :: LayoutInfo -> Doc | 244 | pretty SingleFile {..} = pretty liFile |
247 | ppLayoutInfo SingleFile {..} = ppFileInfo liFile | 245 | pretty MultiFile {..} = vcat $ L.map (pretty . joinFilePath) liFiles |
248 | ppLayoutInfo 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. |
251 | isSingleFile :: LayoutInfo -> Bool | 248 | isSingleFile :: LayoutInfo -> Bool |