brick/programs/Main.hs

52 lines
1.1 KiB
Haskell
Raw Normal View History

2015-05-09 09:09:40 +03:00
{-# LANGUAGE OverloadedStrings #-}
module Main where
2015-05-09 19:56:14 +03:00
import Data.Default
2015-05-09 09:09:40 +03:00
import Graphics.Vty
import System.Exit
import Brick
2015-05-09 10:18:29 +03:00
data St =
2015-05-09 18:37:16 +03:00
St { focus :: FocusRing
, stEditor :: Editor
}
2015-05-09 10:18:29 +03:00
eName :: Name
eName = Name "edit"
2015-05-10 00:28:37 +03:00
drawUI :: St -> [Widget]
drawUI st = [top]
where
top = vBox [ "Top"
, hBorder '-'
, hBox [ " Edit: "
, hLimit 20 $ edit (stEditor st) `withAttr` (cyan `on` blue)
]
]
2015-05-09 09:09:40 +03:00
handleEvent :: Event -> St -> IO St
handleEvent e st =
2015-05-09 09:09:40 +03:00
case e of
EvKey KEsc [] -> exitSuccess
2015-05-09 20:20:31 +03:00
EvKey KEnter [] -> error $ editStr $ stEditor st
ev -> return $ st { stEditor = editEvent ev (stEditor st) }
initialState :: St
initialState =
St { focus = focusRing [eName]
, stEditor = editor eName ""
}
app :: App St
app =
2015-05-09 19:56:14 +03:00
def { appDraw = drawUI
, appChooseCursor = focusRingCursor focus
, appHandleEvent = handleEvent
}
2015-05-09 09:09:40 +03:00
main :: IO ()
main = standardIOConfig
>>= mkVty
>>= runVty app initialState