module Brick.Markup
( Markup
, markup
, (@?)
, GetAttr(..)
)
where
import Lens.Micro ((.~), (&), (^.))
import Control.Monad (forM)
import qualified Data.Text as T
import Data.Text.Markup
import Graphics.Vty (Attr, vertCat, horizCat, string)
import Brick.AttrMap
import Brick.Types
class GetAttr a where
getAttr :: a -> RenderM n Attr
instance GetAttr Attr where
getAttr a = do
c <- getContext
return $ mergeWithDefault a (c^.ctxAttrMapL)
instance GetAttr AttrName where
getAttr = lookupAttrName
(@?) :: T.Text -> AttrName -> Markup AttrName
(@?) = (@@)
markup :: (Eq a, GetAttr a) => Markup a -> Widget n
markup m =
Widget Fixed Fixed $ do
let markupLines = markupToList m
mkLine pairs = do
is <- forM pairs $ \(t, aSrc) -> do
a <- getAttr aSrc
return $ string a $ T.unpack t
return $ horizCat is
lineImgs <- mapM mkLine markupLines
return $ emptyResult & imageL .~ vertCat lineImgs