mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-03 11:41:06 +03:00
fc8cfe3b4a
This change makes it possible for brick to extent the event space using its own event notions in addition those provided by Vty and the application itself. This means we no longer need the user to provide the type and appLiftVtyEvent went away. This makes pattern-matching in event handlers a little noisier with the benefit that we can now add events like mouse clicks or drags to the event type.
46 lines
1.1 KiB
Haskell
46 lines
1.1 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Main where
|
|
|
|
import Data.Monoid ((<>))
|
|
import qualified Graphics.Vty as V
|
|
|
|
import Brick.Main (App(..), defaultMain, resizeOrQuit, neverShowCursor)
|
|
import Brick.Types
|
|
( Widget
|
|
, Padding(..)
|
|
)
|
|
import Brick.Widgets.Core
|
|
( (<=>)
|
|
, (<+>)
|
|
, padLeft
|
|
)
|
|
import Brick.Util (on, fg)
|
|
import Brick.Markup (markup, (@?))
|
|
import Brick.AttrMap (attrMap, AttrMap)
|
|
import Data.Text.Markup ((@@))
|
|
|
|
ui :: Widget ()
|
|
ui = (m1 <=> m2) <+> (padLeft (Pad 1) m3)
|
|
where
|
|
m1 = markup $ ("Hello" @@ fg V.blue) <> ", " <> ("world!" @@ fg V.red)
|
|
m2 = markup $ ("Hello" @? "keyword1") <> ", " <> ("world!" @? "keyword2")
|
|
m3 = markup $ ("Hello," @? "keyword1") <> "\n" <> ("world!" @? "keyword2")
|
|
|
|
theMap :: AttrMap
|
|
theMap = attrMap V.defAttr
|
|
[ ("keyword1", fg V.magenta)
|
|
, ("keyword2", V.white `on` V.blue)
|
|
]
|
|
|
|
app :: App () e ()
|
|
app =
|
|
App { appDraw = const [ui]
|
|
, appHandleEvent = resizeOrQuit
|
|
, appAttrMap = const theMap
|
|
, appStartEvent = return
|
|
, appChooseCursor = neverShowCursor
|
|
}
|
|
|
|
main :: IO ()
|
|
main = defaultMain app ()
|