packages feed

buster-1.2: App/Behaviours/PrintEvents.hs

module App.Behaviours.PrintEvents where

import qualified Data.ByteString as B
import Text.PrettyPrint
import Data.Time
import System.Locale
import App.EventBus

printEventsBehaviour :: Behaviour [EData a]
printEventsBehaviour b = pollAllEventsWith b $ (\(Event n g lifetime edata source t) -> do
    putStrLn.render $ text "name:    " <+> text n $+$
	                  text "source:  " <+> text source $+$
	                  text "group:   " <+> text g $+$
	                  text "ttl:     " <+> text (show lifetime) $+$
	                  text "emitTime:" <+> text (formatTime defaultTimeLocale "%T" t) $+$
	                  (vcat.map showIfPossible $ edata)
    return [])
    where showIfPossible (EString x) = text x
          showIfPossible (EByteString x) = text "ByteString"
          showIfPossible (EByteStringL x) = text "[ByteString]"
          showIfPossible (EInt x) = text (show x)
          showIfPossible (EDouble x) = text (show x)
          showIfPossible (EBool x) = text (show x)
          showIfPossible (EStringL x) = text (show x)
          showIfPossible (EIntL x) = text (show x)
          showIfPossible (EDoubleL x) = text (show x)
          showIfPossible (EBoolL x) = text (show x)
          showIfPossible (EChar x) = char x
          showIfPossible (EOther x) = text "Custom Data"
          showIfPossible (EOtherL x) = text "Custom Data List"
          showIfPossible (EAssoc (x,y)) = text "x -> " <> showIfPossible y
          showIfPossible (EAssocL assocs) = vcat (map showAssoc assocs)
          showAssoc (x, y) = text x <> showIfPossible y