module TextShow.System.IO () where
import Data.Monoid.Compat ((<>))
import Data.Text.Lazy.Builder (Builder, fromString, singleton)
import GHC.IO.Encoding.Failure (CodingFailureMode)
import GHC.IO.Encoding.Types (CodingProgress, TextEncoding(textEncodingName))
import GHC.IO.Handle (HandlePosn(..))
import GHC.IO.Handle.Types (Handle(..))
import System.IO (BufferMode, IOMode, Newline, NewlineMode, SeekMode)
import TextShow.Classes (TextShow(..))
import TextShow.Data.Integral ()
import TextShow.Data.Maybe ()
import TextShow.TH.Internal (deriveTextShow)
instance TextShow Handle where
showb (FileHandle file _) = showbHandleFilePath file
showb (DuplexHandle file _ _) = showbHandleFilePath file
showbHandleFilePath :: FilePath -> Builder
showbHandleFilePath file = "{handle: " <> fromString file <> singleton '}'
$(deriveTextShow ''IOMode)
$(deriveTextShow ''BufferMode)
instance TextShow HandlePosn where
showb (HandlePosn h pos) = showb h <> " at position " <> showbPrec 0 pos
$(deriveTextShow ''SeekMode)
instance TextShow TextEncoding where
showb = fromString . textEncodingName
$(deriveTextShow ''CodingProgress)
$(deriveTextShow ''CodingFailureMode)
$(deriveTextShow ''Newline)
$(deriveTextShow ''NewlineMode)