summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Peer/ClientInfo.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-02 06:43:00 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-02 06:43:00 +0400
commit4de96724e4006589022e08b6ed247784f958b508 (patch)
tree7c7807a4e9425fca1151e1fed909a3643238278f /src/Network/BitTorrent/Peer/ClientInfo.hs
parentdea6c9b2ea1037ee54f1908ebc6a5e193e0cfac6 (diff)
~ Use pretty package for pretty print.
This is a bit faster and pretty!
Diffstat (limited to 'src/Network/BitTorrent/Peer/ClientInfo.hs')
-rw-r--r--src/Network/BitTorrent/Peer/ClientInfo.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Peer/ClientInfo.hs b/src/Network/BitTorrent/Peer/ClientInfo.hs
index ebbecbd7..bf7fcaab 100644
--- a/src/Network/BitTorrent/Peer/ClientInfo.hs
+++ b/src/Network/BitTorrent/Peer/ClientInfo.hs
@@ -12,6 +12,7 @@
12-- > See http://bittorrent.org/beps/bep_0020.html for more information. 12-- > See http://bittorrent.org/beps/bep_0020.html for more information.
13-- 13--
14{-# LANGUAGE OverloadedStrings #-} 14{-# LANGUAGE OverloadedStrings #-}
15{-# LANGUAGE RecordWildCards #-}
15module Network.BitTorrent.Peer.ClientInfo 16module Network.BitTorrent.Peer.ClientInfo
16 ( -- * Info 17 ( -- * Info
17 ClientInfo(..), clientInfo, ppClientInfo, unknownClient 18 ClientInfo(..), clientInfo, ppClientInfo, unknownClient
@@ -30,6 +31,7 @@ import Control.Applicative
30import Data.ByteString (ByteString) 31import Data.ByteString (ByteString)
31import qualified Data.ByteString.Char8 as BC 32import qualified Data.ByteString.Char8 as BC
32import Data.Serialize.Get 33import Data.Serialize.Get
34import Text.PrettyPrint
33 35
34import Network.BitTorrent.Peer.ID 36import Network.BitTorrent.Peer.ID
35 37
@@ -163,8 +165,8 @@ parseImpl = f . BC.unpack
163 f _ = IUnknown 165 f _ = IUnknown
164 166
165-- | Format client implementation info in human readable form. 167-- | Format client implementation info in human readable form.
166ppClientImpl :: ClientImpl -> String 168ppClientImpl :: ClientImpl -> Doc
167ppClientImpl = tail . show 169ppClientImpl = text . tail . show
168 170
169unknownImpl :: ClientImpl 171unknownImpl :: ClientImpl
170unknownImpl = IUnknown 172unknownImpl = IUnknown
@@ -174,8 +176,8 @@ unknownImpl = IUnknown
174type ClientVersion = ByteString 176type ClientVersion = ByteString
175 177
176-- | Format client implementation version in human readable form. 178-- | Format client implementation version in human readable form.
177ppClientVersion :: ClientVersion -> String 179ppClientVersion :: ClientVersion -> Doc
178ppClientVersion = BC.unpack 180ppClientVersion = text . BC.unpack
179 181
180unknownVersion :: ClientVersion 182unknownVersion :: ClientVersion
181unknownVersion = "0000" 183unknownVersion = "0000"
@@ -189,9 +191,10 @@ data ClientInfo = ClientInfo {
189 } deriving (Show, Eq, Ord) 191 } deriving (Show, Eq, Ord)
190 192
191-- | Format client implementation in human readable form. 193-- | Format client implementation in human readable form.
192ppClientInfo :: ClientInfo -> String 194ppClientInfo :: ClientInfo -> Doc
193ppClientInfo ci = ppClientImpl (ciImpl ci) ++ " version " 195ppClientInfo ClientInfo {..} =
194 ++ ppClientVersion (ciVersion ci) 196 ppClientImpl ciImpl <+> "version" <+> ppClientVersion ciVersion
197
195 198
196-- | Unrecognized client implementation. 199-- | Unrecognized client implementation.
197unknownClient :: ClientInfo 200unknownClient :: ClientInfo