mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-09-11 23:57:22 +03:00
DialogDemo: use explicit imports
This commit is contained in:
parent
7833b2cf44
commit
ceda506b57
@ -2,57 +2,62 @@
|
||||
module Main where
|
||||
|
||||
import Data.Monoid
|
||||
import Graphics.Vty hiding (translate)
|
||||
import qualified Graphics.Vty as V
|
||||
|
||||
import Brick.Main
|
||||
import qualified Brick.Main as M
|
||||
import Brick.Widgets.Core
|
||||
import Brick.Widgets.Dialog
|
||||
import Brick.Widgets.Center
|
||||
import Brick.AttrMap
|
||||
import Brick.Util
|
||||
import Brick.Types
|
||||
( Widget
|
||||
, Padding(..)
|
||||
, padAll
|
||||
, 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
|
||||
|
||||
data Choice = Red | Blue | Green
|
||||
deriving Show
|
||||
|
||||
drawUI :: Dialog Choice -> [Widget]
|
||||
drawUI :: D.Dialog Choice -> [Widget]
|
||||
drawUI d = [ui]
|
||||
where
|
||||
ui = renderDialog d $ hCenter $ padAll (Pad 1) $ str "This is the dialog body."
|
||||
ui = D.renderDialog d $ C.hCenter $ padAll (Pad 1) $ str "This is the dialog body."
|
||||
|
||||
appEvent :: Dialog Choice -> Event -> EventM (Next (Dialog Choice))
|
||||
appEvent :: D.Dialog Choice -> V.Event -> M.EventM (M.Next (D.Dialog Choice))
|
||||
appEvent d ev =
|
||||
case ev of
|
||||
EvKey KEsc [] -> halt d
|
||||
EvKey KEnter [] -> halt d
|
||||
_ -> continue $ handleEvent ev d
|
||||
V.EvKey V.KEsc [] -> M.halt d
|
||||
V.EvKey V.KEnter [] -> M.halt d
|
||||
_ -> M.continue $ T.handleEvent ev d
|
||||
|
||||
initialState :: Dialog Choice
|
||||
initialState = dialog "dialog" (Just "Title") (Just (0, choices)) 50
|
||||
initialState :: D.Dialog Choice
|
||||
initialState = D.dialog "dialog" (Just "Title") (Just (0, choices)) 50
|
||||
where
|
||||
choices = [ ("Red", Red)
|
||||
, ("Blue", Blue)
|
||||
, ("Green", Green)
|
||||
]
|
||||
|
||||
theMap :: AttrMap
|
||||
theMap = attrMap defAttr
|
||||
[ (dialogAttr, white `on` blue)
|
||||
, (buttonAttr, black `on` white)
|
||||
, (buttonSelectedAttr, bg yellow)
|
||||
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)
|
||||
]
|
||||
|
||||
theApp :: App (Dialog Choice) Event
|
||||
theApp :: M.App (D.Dialog Choice) V.Event
|
||||
theApp =
|
||||
App { appDraw = drawUI
|
||||
, appChooseCursor = showFirstCursor
|
||||
, appHandleEvent = appEvent
|
||||
, appStartEvent = return
|
||||
, appAttrMap = const theMap
|
||||
, appMakeVtyEvent = id
|
||||
}
|
||||
M.App { M.appDraw = drawUI
|
||||
, M.appChooseCursor = M.showFirstCursor
|
||||
, M.appHandleEvent = appEvent
|
||||
, M.appStartEvent = return
|
||||
, M.appAttrMap = const theMap
|
||||
, M.appMakeVtyEvent = id
|
||||
}
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
d <- defaultMain theApp initialState
|
||||
putStrLn $ "You chose: " <> show (dialogSelection d)
|
||||
d <- M.defaultMain theApp initialState
|
||||
putStrLn $ "You chose: " <> show (D.dialogSelection d)
|
||||
|
Loading…
Reference in New Issue
Block a user