module Graphics.Vty.Output.Mock
( MockData
, mockTerminal
)
where
import Graphics.Vty.Image (DisplayRegion)
import Graphics.Vty.Output.Interface
import Blaze.ByteString.Builder.Word (writeWord8)
import Control.Monad.Trans
import qualified Data.ByteString as BS
import Data.IORef
import qualified Data.String.UTF8 as UTF8
type MockData = IORef (UTF8.UTF8 BS.ByteString)
mockTerminal :: (Applicative m, MonadIO m) => DisplayRegion -> m (MockData, Output)
mockTerminal r = liftIO $ do
outRef <- newIORef undefined
newAssumedStateRef <- newIORef initialAssumedState
let t = Output
{ terminalID = "mock terminal"
, releaseTerminal = return ()
, reserveDisplay = return ()
, releaseDisplay = return ()
, ringTerminalBell = return ()
, supportsBell = return False
, displayBounds = return r
, outputByteBuffer = \bytes -> do
putStrLn $ "mock outputByteBuffer of " ++ show (BS.length bytes) ++ " bytes"
writeIORef outRef $ UTF8.fromRep bytes
, contextColorCount = 16
, supportsCursorVisibility = True
, supportsMode = const False
, setMode = const $ const $ return ()
, getModeStatus = const $ return False
, assumedStateRef = newAssumedStateRef
, mkDisplayContext = \tActual rActual -> return $ DisplayContext
{ contextRegion = rActual
, contextDevice = tActual
, writeMoveCursor = \_x _y -> writeWord8 $ toEnum $ fromEnum 'M'
, writeShowCursor = writeWord8 $ toEnum $ fromEnum 'S'
, writeHideCursor = writeWord8 $ toEnum $ fromEnum 'H'
, writeSetAttr = \_fattr _diffs _attr -> writeWord8 $ toEnum $ fromEnum 'A'
, writeDefaultAttr = writeWord8 $ toEnum $ fromEnum 'D'
, writeRowEnd = writeWord8 $ toEnum $ fromEnum 'E'
, inlineHack = return ()
}
}
return (outRef, t)