simple text editor using the bricks library

This commit is contained in:
Johannes Winklehner 2016-07-21 13:23:49 +02:00
parent c9200c190d
commit 9fed792c40

35
editor.hs Normal file
View file

@ -0,0 +1,35 @@
import Brick
import qualified Brick.Widgets.Edit as E
import qualified Graphics.Vty as V
data Name = Text deriving (Ord, Show, Eq)
type St = E.Editor Name
initialState :: St
initialState = E.editor Text (str . unlines) Nothing ""
drawUI :: St -> [Widget Name]
drawUI st = [E.renderEditor True st]
appCursor :: St -> [CursorLocation Name] -> Maybe (CursorLocation Name)
appCursor st c = Just (head c)
appEvent :: St -> V.Event -> EventM Name (Next St)
appEvent st ev =
case ev of
V.EvKey V.KEsc [] -> halt st
_ -> continue =<< E.handleEditorEvent ev st
theApp :: App St V.Event Name
theApp =
App { appDraw = drawUI
, appChooseCursor = appCursor
, appHandleEvent = appEvent
, appStartEvent = return
, appAttrMap = const (attrMap V.defAttr [ ])
, appLiftVtyEvent = id
}
main = do
st <- defaultMain theApp initialState
putStrLn $ unlines $ E.getEditContents $ st