2022-07-04 19:21:55 +03:00
|
|
|
{-# LANGUAGE CPP #-}
|
2022-07-01 04:54:30 +03:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
|
|
|
module Render
|
2022-07-04 18:47:06 +03:00
|
|
|
( main
|
2022-07-01 04:54:30 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Brick
|
2022-07-04 19:14:23 +03:00
|
|
|
import Control.Monad (when)
|
2022-07-04 19:20:31 +03:00
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
|
|
|
import Data.Monoid
|
|
|
|
#endif
|
2022-07-01 04:54:30 +03:00
|
|
|
import qualified Graphics.Vty as V
|
|
|
|
import Brick.Widgets.Border (hBorder)
|
2022-07-05 18:15:18 +03:00
|
|
|
import Control.Exception (SomeException, try)
|
2022-07-01 04:54:30 +03:00
|
|
|
|
|
|
|
region :: V.DisplayRegion
|
|
|
|
region = (30, 10)
|
|
|
|
|
|
|
|
renderDisplay :: Ord n => [Widget n] -> IO ()
|
|
|
|
renderDisplay ws = do
|
2022-07-04 18:46:47 +03:00
|
|
|
outp <- V.outputForConfig V.defaultConfig
|
|
|
|
ctx <- V.displayContext outp region
|
|
|
|
V.outputPicture ctx (renderWidget Nothing ws region)
|
2022-07-04 18:53:35 +03:00
|
|
|
V.releaseDisplay outp
|
2022-07-04 00:49:59 +03:00
|
|
|
|
|
|
|
myWidget :: Widget ()
|
|
|
|
myWidget = str "Why" <=> hBorder <=> str "not?"
|
2022-07-01 04:54:30 +03:00
|
|
|
|
2022-07-04 18:46:47 +03:00
|
|
|
-- Since you can't Read a Picture, we have to compare the result with
|
|
|
|
-- the Shown one
|
2022-07-04 18:53:35 +03:00
|
|
|
expectedResult :: String
|
2022-07-04 19:14:23 +03:00
|
|
|
expectedResult = "Picture {picCursor = NoCursor, picLayers = [VertJoin {partTop = VertJoin {partTop = HorizText {attr = Attr {attrStyle = Default, attrForeColor = Default, attrBackColor = Default, attrURL = Default}, displayText = \"Why \", outputWidth = 30, charWidth = 30}, partBottom = VertJoin {partTop = HorizText {attr = Attr {attrStyle = Default, attrForeColor = Default, attrBackColor = Default, attrURL = Default}, displayText = \"\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\\9472\", outputWidth = 30, charWidth = 30}, partBottom = HorizText {attr = Attr {attrStyle = Default, attrForeColor = Default, attrBackColor = Default, attrURL = Default}, displayText = \"not? \", outputWidth = 30, charWidth = 30}, outputWidth = 30, outputHeight = 2}, outputWidth = 30, outputHeight = 3}, partBottom = BGFill {outputWidth = 30, outputHeight = 7}, outputWidth = 30, outputHeight = 10}], picBackground = Background {backgroundChar = ' ', backgroundAttr = Attr {attrStyle = Default, attrForeColor = Default, attrBackColor = Default, attrURL = Default}}}"
|
2022-07-01 04:54:30 +03:00
|
|
|
|
|
|
|
main :: IO Bool
|
2022-07-04 18:46:47 +03:00
|
|
|
main = do
|
2022-07-05 18:15:18 +03:00
|
|
|
result <- try (renderDisplay [myWidget]) :: IO (Either SomeException ())
|
2022-07-04 18:46:47 +03:00
|
|
|
case result of
|
2022-07-04 18:53:35 +03:00
|
|
|
Left _ -> do
|
2022-07-04 19:09:13 +03:00
|
|
|
putStrLn "Terminal is not available, skipping test"
|
2022-07-04 19:00:28 +03:00
|
|
|
-- Even though we could not actually run the test, we return
|
|
|
|
-- True here to prevent the absence of a terminal from
|
|
|
|
-- causing a test suite failure in an automated context.
|
|
|
|
-- This means that this test effectively doesn't get
|
|
|
|
-- considered at all in the automated context.
|
|
|
|
return True
|
2022-07-04 18:53:35 +03:00
|
|
|
Right () -> do
|
|
|
|
let matched = actualResult == expectedResult
|
|
|
|
actualResult = show (renderWidget Nothing [myWidget] region)
|
|
|
|
msg = if matched then "rendering match" else "rendering mismatch"
|
|
|
|
|
|
|
|
putStrLn ""
|
|
|
|
putStrLn $ "renderWidget test outcome: " <> msg
|
2022-07-04 19:14:23 +03:00
|
|
|
|
|
|
|
when (not matched) $ do
|
|
|
|
putStrLn "Expected result:"
|
|
|
|
putStrLn expectedResult
|
|
|
|
|
|
|
|
putStrLn "Actual result:"
|
|
|
|
putStrLn actualResult
|
|
|
|
|
2022-07-04 18:53:35 +03:00
|
|
|
return matched
|