#if !defined(__GHCJS__) && !defined(mingw32_HOST_OS) && MIN_VERSION_base(4,4,0)
#endif
module TextShow.GHC.Event (
#if defined(__GHCJS__) || defined(mingw32_HOST_OS) || !(MIN_VERSION_base(4,4,0))
) where
#else
showbEvent
, showbFdKeyPrec
# if MIN_VERSION_base(4,8,1)
, showbLifetime
# endif
) where
import Data.List (intersperse)
import Data.Maybe (catMaybes)
import Data.Monoid.Compat ((<>))
import Data.Text.Lazy.Builder (Builder, singleton)
import GHC.Event (Event, FdKey, evtRead, evtWrite)
import Language.Haskell.TH.Lib (conT, varE)
import Prelude ()
import Prelude.Compat
import TextShow.Classes (TextShow(showb, showbPrec))
import TextShow.Data.Integral ()
import TextShow.System.Posix.Types ()
import TextShow.TH.Internal (deriveTextShow)
import TextShow.TH.Names (evtCloseValName, eventIsValName,
fdKeyTypeName, uniqueTypeName, asInt64ValName)
# if MIN_VERSION_base(4,8,1)
import GHC.Event (Lifetime)
# endif
#include "inline.h"
showbEvent :: Event -> Builder
showbEvent e = singleton '[' <> mconcat (intersperse "," $ catMaybes
[ evtRead `so` "evtRead"
, evtWrite `so` "evtWrite"
, $(varE evtCloseValName) `so` "evtClose"
]) <> singleton ']'
where
so :: Event -> Builder -> Maybe Builder
ev `so` disp | $(varE eventIsValName) e ev = Just disp
| otherwise = Nothing
showbFdKeyPrec :: Int -> FdKey -> Builder
showbFdKeyPrec = showbPrec
# if MIN_VERSION_base(4,8,1)
showbLifetime :: Lifetime -> Builder
showbLifetime = showb
# endif
instance TextShow Event where
showb = showbEvent
$(deriveTextShow fdKeyTypeName)
instance TextShow $(conT uniqueTypeName) where
showb = showb . $(varE asInt64ValName)
INLINE_INST_FUN(showb)
# if MIN_VERSION_base(4,8,1)
$(deriveTextShow ''Lifetime)
# endif
#endif