brick/programs/MarkupDemo.hs

49 lines
1.2 KiB
Haskell
Raw Normal View History

{-# LANGUAGE CPP #-}
2015-06-29 06:16:51 +03:00
{-# LANGUAGE OverloadedStrings #-}
module Main where
#if !(MIN_VERSION_base(4,11,0))
2015-06-29 06:16:51 +03:00
import Data.Monoid ((<>))
#endif
2015-07-10 23:28:23 +03:00
import qualified Graphics.Vty as V
2015-06-29 06:16:51 +03:00
2015-07-10 23:28:23 +03:00
import Brick.Main (App(..), defaultMain, resizeOrQuit, neverShowCursor)
import Brick.Types
2015-07-10 23:28:23 +03:00
( Widget
, Padding(..)
)
import Brick.Widgets.Core
( (<=>)
, (<+>)
, padLeft
2015-07-10 23:28:23 +03:00
)
import Brick.Util (on, fg)
import Brick.Markup (markup, (@?))
import Brick.AttrMap (attrMap, AttrMap)
2015-06-29 06:16:51 +03:00
import Data.Text.Markup ((@@))
ui :: Widget ()
ui = (m1 <=> m2) <+> (padLeft (Pad 1) m3)
2015-06-29 06:16:51 +03:00
where
2015-07-10 23:28:23 +03:00
m1 = markup $ ("Hello" @@ fg V.blue) <> ", " <> ("world!" @@ fg V.red)
2015-06-29 06:16:51 +03:00
m2 = markup $ ("Hello" @? "keyword1") <> ", " <> ("world!" @? "keyword2")
m3 = markup $ ("Hello," @? "keyword1") <> "\n" <> ("world!" @? "keyword2")
2015-06-29 06:16:51 +03:00
theMap :: AttrMap
2015-07-10 23:28:23 +03:00
theMap = attrMap V.defAttr
[ ("keyword1", fg V.magenta)
, ("keyword2", V.white `on` V.blue)
2015-06-29 06:16:51 +03:00
]
app :: App () e ()
2015-06-29 06:16:51 +03:00
app =
App { appDraw = const [ui]
, appHandleEvent = resizeOrQuit
2015-06-29 06:16:51 +03:00
, appAttrMap = const theMap
, appStartEvent = return
2015-06-29 06:16:51 +03:00
, appChooseCursor = neverShowCursor
}
main :: IO ()
main = defaultMain app ()