{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Graphics.Vty.Output.Mock
( MockData
, mockTerminal
)
where
import Graphics.Vty.Image (DisplayRegion)
import Graphics.Vty.Attributes.Color (ColorMode(ColorMode16))
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 :: forall (m :: * -> *).
(Applicative m, MonadIO m) =>
DisplayRegion -> m (MockData, Output)
mockTerminal DisplayRegion
r = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
MockData
outRef <- forall a. a -> IO (IORef a)
newIORef forall a. HasCallStack => a
undefined
IORef AssumedState
newAssumedStateRef <- forall a. a -> IO (IORef a)
newIORef AssumedState
initialAssumedState
let t :: Output
t = Output
{ terminalID :: String
terminalID = String
"mock terminal"
, releaseTerminal :: IO ()
releaseTerminal = forall (m :: * -> *) a. Monad m => a -> m a
return ()
, reserveDisplay :: IO ()
reserveDisplay = forall (m :: * -> *) a. Monad m => a -> m a
return ()
, releaseDisplay :: IO ()
releaseDisplay = forall (m :: * -> *) a. Monad m => a -> m a
return ()
, ringTerminalBell :: IO ()
ringTerminalBell = forall (m :: * -> *) a. Monad m => a -> m a
return ()
, supportsBell :: IO Bool
supportsBell = forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, supportsItalics :: IO Bool
supportsItalics = forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, supportsStrikethrough :: IO Bool
supportsStrikethrough = forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, setDisplayBounds :: DisplayRegion -> IO ()
setDisplayBounds = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return ()
, displayBounds :: IO DisplayRegion
displayBounds = forall (m :: * -> *) a. Monad m => a -> m a
return DisplayRegion
r
, outputByteBuffer :: ByteString -> IO ()
outputByteBuffer = \ByteString
bytes -> do
String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
"mock outputByteBuffer of " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (ByteString -> Int
BS.length ByteString
bytes) forall a. [a] -> [a] -> [a]
++ String
" bytes"
forall a. IORef a -> a -> IO ()
writeIORef MockData
outRef forall a b. (a -> b) -> a -> b
$ forall string. string -> UTF8 string
UTF8.fromRep ByteString
bytes
, supportsCursorVisibility :: Bool
supportsCursorVisibility = Bool
True
, supportsMode :: Mode -> Bool
supportsMode = forall a b. a -> b -> a
const Bool
False
, setMode :: Mode -> Bool -> IO ()
setMode = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return ()
, getModeStatus :: Mode -> IO Bool
getModeStatus = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
, assumedStateRef :: IORef AssumedState
assumedStateRef = IORef AssumedState
newAssumedStateRef
, outputColorMode :: ColorMode
outputColorMode = ColorMode
ColorMode16
, mkDisplayContext :: Output -> DisplayRegion -> IO DisplayContext
mkDisplayContext = \Output
tActual DisplayRegion
rActual -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ DisplayContext
{ contextRegion :: DisplayRegion
contextRegion = DisplayRegion
rActual
, contextDevice :: Output
contextDevice = Output
tActual
, writeMoveCursor :: Int -> Int -> Write
writeMoveCursor = \Int
_x Int
_y -> Word8 -> Write
writeWord8 forall a b. (a -> b) -> a -> b
$ forall a. Enum a => Int -> a
toEnum forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum Char
'M'
, writeShowCursor :: Write
writeShowCursor = Word8 -> Write
writeWord8 forall a b. (a -> b) -> a -> b
$ forall a. Enum a => Int -> a
toEnum forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum Char
'S'
, writeHideCursor :: Write
writeHideCursor = Word8 -> Write
writeWord8 forall a b. (a -> b) -> a -> b
$ forall a. Enum a => Int -> a
toEnum forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum Char
'H'
, writeSetAttr :: Bool -> FixedAttr -> Attr -> DisplayAttrDiff -> Write
writeSetAttr = \Bool
_ FixedAttr
_fattr Attr
_diffs DisplayAttrDiff
_attr -> Word8 -> Write
writeWord8 forall a b. (a -> b) -> a -> b
$ forall a. Enum a => Int -> a
toEnum forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum Char
'A'
, writeDefaultAttr :: Bool -> Write
writeDefaultAttr = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ Word8 -> Write
writeWord8 forall a b. (a -> b) -> a -> b
$ forall a. Enum a => Int -> a
toEnum forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum Char
'D'
, writeRowEnd :: Write
writeRowEnd = Word8 -> Write
writeWord8 forall a b. (a -> b) -> a -> b
$ forall a. Enum a => Int -> a
toEnum forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum Char
'E'
, inlineHack :: IO ()
inlineHack = forall (m :: * -> *) a. Monad m => a -> m a
return ()
}
}
forall (m :: * -> *) a. Monad m => a -> m a
return (MockData
outRef, Output
t)