brick/programs/Main.hs

43 lines
1004 B
Haskell
Raw Normal View History

2015-05-09 09:09:40 +03:00
{-# LANGUAGE OverloadedStrings #-}
module Main where
2015-05-09 10:18:29 +03:00
import Data.Maybe
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
drawUI :: St -> Widget
drawUI st =
2015-05-09 18:37:16 +03:00
vBox [ hLimit 15 $ edit (stEditor st) `withAttr` (cyan `on` blue)
2015-05-09 11:23:25 +03:00
, hBorder '-'
, "stuff and things"
]
2015-05-09 09:09:40 +03:00
handleEvent :: Event -> St -> Either ExitCode St
handleEvent e st =
2015-05-09 09:09:40 +03:00
case e of
EvKey KEsc [] -> Left ExitSuccess
2015-05-09 18:37:16 +03:00
ev -> Right $ st { stEditor = editEvent ev (stEditor st) }
pickCursor :: St -> [CursorLocation] -> Maybe CursorLocation
pickCursor st ls =
listToMaybe $ filter (\cl -> cursorLocationName cl == (focusGetCurrent $ focus st)) ls
initialState :: St
initialState =
let eName = Name "edit"
2015-05-09 18:37:16 +03:00
in St { focus = focusRing [eName]
2015-05-09 11:23:25 +03:00
, stEditor = editor eName ""
}
2015-05-09 09:09:40 +03:00
main :: IO ()
main = standardIOConfig
>>= mkVty
>>= runVty drawUI pickCursor handleEvent initialState