mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-27 02:53:16 +03:00
Simplify edit demo application state
This commit is contained in:
parent
34e14bf1dd
commit
6c762fb95b
@ -1,5 +1,4 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
@ -14,35 +13,27 @@ import Brick.Widgets.Edit
|
|||||||
import Brick.AttrMap
|
import Brick.AttrMap
|
||||||
import Brick.Util
|
import Brick.Util
|
||||||
|
|
||||||
data St =
|
drawUI :: Editor -> [Widget]
|
||||||
St { _stEditor :: Editor
|
drawUI e = [ui]
|
||||||
}
|
|
||||||
|
|
||||||
makeLenses ''St
|
|
||||||
|
|
||||||
drawUI :: St -> [Widget]
|
|
||||||
drawUI st = [ui]
|
|
||||||
where
|
where
|
||||||
ui = center $ ("Input: " <+> (hLimit 30 $ renderEditor $ st^.stEditor))
|
ui = center $ ("Input: " <+> (hLimit 30 $ renderEditor e))
|
||||||
|
|
||||||
appEvent :: Event -> St -> EventM (Next St)
|
appEvent :: Event -> Editor -> EventM (Next Editor)
|
||||||
appEvent e st =
|
appEvent ev e =
|
||||||
case e of
|
case ev of
|
||||||
EvKey KEsc [] -> halt st
|
EvKey KEsc [] -> halt e
|
||||||
EvKey KEnter [] -> halt st
|
EvKey KEnter [] -> halt e
|
||||||
ev -> continue $ st & stEditor %~ (handleEvent ev)
|
_ -> continue $ handleEvent ev e
|
||||||
|
|
||||||
initialState :: St
|
initialState :: Editor
|
||||||
initialState =
|
initialState = editor (Name "edit") str ""
|
||||||
St { _stEditor = editor (Name "edit") str ""
|
|
||||||
}
|
|
||||||
|
|
||||||
theMap :: AttrMap
|
theMap :: AttrMap
|
||||||
theMap = attrMap defAttr
|
theMap = attrMap defAttr
|
||||||
[ (editAttr, white `on` blue)
|
[ (editAttr, white `on` blue)
|
||||||
]
|
]
|
||||||
|
|
||||||
theApp :: App St Event
|
theApp :: App Editor Event
|
||||||
theApp =
|
theApp =
|
||||||
App { appDraw = drawUI
|
App { appDraw = drawUI
|
||||||
, appChooseCursor = showFirstCursor
|
, appChooseCursor = showFirstCursor
|
||||||
@ -53,5 +44,5 @@ theApp =
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
st <- defaultMain theApp initialState
|
e <- defaultMain theApp initialState
|
||||||
putStrLn $ "You entered: " <> (st^.stEditor.editContentsL)
|
putStrLn $ "You entered: " <> (e^.editContentsL)
|
||||||
|
Loading…
Reference in New Issue
Block a user