2015-07-09 00:47:39 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2018-03-17 19:03:30 +03:00
|
|
|
{-# LANGUAGE CPP #-}
|
2015-07-09 00:47:39 +03:00
|
|
|
module Main where
|
|
|
|
|
2018-03-17 19:03:30 +03:00
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
2015-07-09 00:47:39 +03:00
|
|
|
import Data.Monoid
|
2018-03-17 19:03:30 +03:00
|
|
|
#endif
|
2015-07-10 23:09:10 +03:00
|
|
|
import qualified Graphics.Vty as V
|
2015-07-09 00:47:39 +03:00
|
|
|
|
2015-07-10 23:09:10 +03:00
|
|
|
import qualified Brick.Main as M
|
2015-08-20 05:40:06 +03:00
|
|
|
import Brick.Types
|
2015-07-10 23:09:10 +03:00
|
|
|
( Widget
|
2016-10-26 06:19:31 +03:00
|
|
|
, BrickEvent(..)
|
2015-08-20 05:40:06 +03:00
|
|
|
)
|
|
|
|
import Brick.Widgets.Core
|
|
|
|
( padAll
|
2015-07-10 23:09:10 +03:00
|
|
|
, str
|
|
|
|
)
|
|
|
|
import qualified Brick.Widgets.Dialog as D
|
|
|
|
import qualified Brick.Widgets.Center as C
|
|
|
|
import qualified Brick.AttrMap as A
|
|
|
|
import Brick.Util (on, bg)
|
|
|
|
import qualified Brick.Types as T
|
2015-07-09 00:47:39 +03:00
|
|
|
|
|
|
|
data Choice = Red | Blue | Green
|
|
|
|
deriving Show
|
|
|
|
|
2016-03-07 19:52:53 +03:00
|
|
|
drawUI :: D.Dialog Choice -> [Widget ()]
|
2015-07-09 00:47:39 +03:00
|
|
|
drawUI d = [ui]
|
|
|
|
where
|
2015-07-18 07:09:56 +03:00
|
|
|
ui = D.renderDialog d $ C.hCenter $ padAll 1 $ str "This is the dialog body."
|
2015-07-09 00:47:39 +03:00
|
|
|
|
2022-07-17 09:10:03 +03:00
|
|
|
appEvent :: BrickEvent () e -> T.EventM () (D.Dialog Choice) ()
|
|
|
|
appEvent (VtyEvent ev) =
|
2015-07-09 00:47:39 +03:00
|
|
|
case ev of
|
2022-07-17 09:10:03 +03:00
|
|
|
V.EvKey V.KEsc [] -> M.halt
|
|
|
|
V.EvKey V.KEnter [] -> M.halt
|
|
|
|
_ -> D.handleDialogEvent ev
|
|
|
|
appEvent _ = return ()
|
2015-07-09 00:47:39 +03:00
|
|
|
|
2016-03-07 19:52:53 +03:00
|
|
|
initialState :: D.Dialog Choice
|
|
|
|
initialState = D.dialog (Just "Title") (Just (0, choices)) 50
|
2015-07-09 00:47:39 +03:00
|
|
|
where
|
|
|
|
choices = [ ("Red", Red)
|
|
|
|
, ("Blue", Blue)
|
|
|
|
, ("Green", Green)
|
|
|
|
]
|
|
|
|
|
2015-07-10 23:09:10 +03:00
|
|
|
theMap :: A.AttrMap
|
|
|
|
theMap = A.attrMap V.defAttr
|
|
|
|
[ (D.dialogAttr, V.white `on` V.blue)
|
|
|
|
, (D.buttonAttr, V.black `on` V.white)
|
|
|
|
, (D.buttonSelectedAttr, bg V.yellow)
|
2015-07-09 00:47:39 +03:00
|
|
|
]
|
|
|
|
|
2016-10-26 06:19:31 +03:00
|
|
|
theApp :: M.App (D.Dialog Choice) e ()
|
2015-07-09 00:47:39 +03:00
|
|
|
theApp =
|
2015-07-10 23:09:10 +03:00
|
|
|
M.App { M.appDraw = drawUI
|
|
|
|
, M.appChooseCursor = M.showFirstCursor
|
|
|
|
, M.appHandleEvent = appEvent
|
2022-07-17 09:10:03 +03:00
|
|
|
, M.appStartEvent = return ()
|
2015-07-10 23:09:10 +03:00
|
|
|
, M.appAttrMap = const theMap
|
|
|
|
}
|
2015-07-09 00:47:39 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2015-07-10 23:09:10 +03:00
|
|
|
d <- M.defaultMain theApp initialState
|
|
|
|
putStrLn $ "You chose: " <> show (D.dialogSelection d)
|