brick/programs/Main.hs

47 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 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 =
St { msg :: String
, focus :: FocusRing
, stEditor :: Editor
}
2015-05-09 10:18:29 +03:00
drawUI :: St -> Widget
drawUI st =
2015-05-09 11:23:25 +03:00
vBox [ edit (stEditor st) `withAttr` (cyan `on` blue)
, 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
EvKey (KChar '\t') [] -> Right $ st { focus = focusNext $ focus st }
EvKey (KChar c) [] -> Right $ st { msg = msg st ++ [c] }
_ -> Right 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 11:23:25 +03:00
in St { msg = ""
, focus = focusRing [eName]
, stEditor = editor eName ""
}
2015-05-09 09:09:40 +03:00
main :: IO ()
main = standardIOConfig
>>= mkVty
>>= runVty drawUI pickCursor handleEvent initialState