aboutsummaryrefslogtreecommitdiff
path: root/server/src/Thermoprint/Server/Printer/Debug.hs
blob: 721ec84128f28956fe586b8daadac90b10d1415f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TemplateHaskell       #-}

module Thermoprint.Server.Printer.Debug
       ( debugPrint
       ) where

import Control.Monad.IO.Class
import Control.Monad.Trans.Resource
import Control.Monad.Logger

import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as TL

import qualified Data.Text as T

import Thermoprint.Printout
import Thermoprint.Server.Printer

import Data.List (intersperse)
import Data.Foldable (toList)
import Data.Monoid

debugPrint :: PrinterMethod
debugPrint = PM $ (>> return Nothing) . $(logDebugS) "Printer.Debug" . T.pack . show . cotext' 

cotext' :: Printout -> Text
cotext' = mconcat . intersperse "\n\n" . map (mconcat . map cotext'' . toList) . toList
  where
    cotext'' (Cooked b) = cotext b
    cotext'' (Raw _)    = "[Raw]"