brick/programs/EditDemo.hs

49 lines
1.1 KiB
Haskell
Raw Normal View History

2015-06-28 22:45:26 +03:00
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Monoid
import Graphics.Vty hiding (translate)
import Brick.Main
2015-07-08 03:00:42 +03:00
import Brick.Types
2015-06-28 22:45:26 +03:00
import Brick.Widgets.Core
import Brick.Widgets.Center
import Brick.Widgets.Edit
import Brick.AttrMap
import Brick.Util
2015-06-28 23:24:36 +03:00
drawUI :: Editor -> [Widget]
drawUI e = [ui]
2015-06-28 22:45:26 +03:00
where
2015-06-30 20:07:53 +03:00
ui = center $ "Input: " <+> (hLimit 30 $ renderEditor e)
2015-06-28 22:45:26 +03:00
appEvent :: Editor -> Event -> EventM (Next Editor)
appEvent e ev =
2015-06-28 23:24:36 +03:00
case ev of
EvKey KEsc [] -> halt e
EvKey KEnter [] -> halt e
_ -> continue $ handleEvent ev e
2015-06-28 22:45:26 +03:00
2015-06-28 23:24:36 +03:00
initialState :: Editor
initialState = editor (Name "edit") str ""
2015-06-28 22:45:26 +03:00
theMap :: AttrMap
theMap = attrMap defAttr
[ (editAttr, white `on` blue)
]
2015-06-28 23:24:36 +03:00
theApp :: App Editor Event
2015-06-28 22:45:26 +03:00
theApp =
App { appDraw = drawUI
, appChooseCursor = showFirstCursor
, appHandleEvent = appEvent
, appStartEvent = return
2015-06-28 22:45:26 +03:00
, appAttrMap = const theMap
, appMakeVtyEvent = id
}
main :: IO ()
main = do
2015-06-28 23:24:36 +03:00
e <- defaultMain theApp initialState
putStrLn $ "You entered: " <> (getEditContents e)