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
|
|
|
|
2015-07-01 23:05:28 +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
|
2015-07-01 05:15:29 +03:00
|
|
|
, 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
|
2015-07-10 00:32:20 +03:00
|
|
|
putStrLn $ "You entered: " <> (getEditContents e)
|