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
|
|
|
|
|
2015-05-09 10:45:46 +03:00
|
|
|
import Brick
|
2015-05-09 10:18:29 +03:00
|
|
|
|
2015-05-09 10:45:46 +03:00
|
|
|
data St =
|
2015-05-09 18:37:16 +03:00
|
|
|
St { focus :: FocusRing
|
2015-05-09 11:19:09 +03:00
|
|
|
, stEditor :: Editor
|
2015-05-09 10:45:46 +03:00
|
|
|
}
|
2015-05-09 10:18:29 +03:00
|
|
|
|
2015-05-09 10:45:46 +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
|
|
|
|
2015-05-09 10:45:46 +03:00
|
|
|
handleEvent :: Event -> St -> Either ExitCode St
|
|
|
|
handleEvent e st =
|
2015-05-09 09:09:40 +03:00
|
|
|
case e of
|
2015-05-09 10:45:46 +03:00
|
|
|
EvKey KEsc [] -> Left ExitSuccess
|
2015-05-09 18:37:16 +03:00
|
|
|
ev -> Right $ st { stEditor = editEvent ev (stEditor st) }
|
2015-05-09 10:45:46 +03:00
|
|
|
|
|
|
|
pickCursor :: St -> [CursorLocation] -> Maybe CursorLocation
|
|
|
|
pickCursor st ls =
|
2015-05-09 10:57:14 +03:00
|
|
|
listToMaybe $ filter (\cl -> cursorLocationName cl == (focusGetCurrent $ focus st)) ls
|
2015-05-09 10:45:46 +03:00
|
|
|
|
|
|
|
initialState :: St
|
|
|
|
initialState =
|
2015-05-09 11:19:09 +03:00
|
|
|
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
|
2015-05-09 10:45:46 +03:00
|
|
|
>>= runVty drawUI pickCursor handleEvent initialState
|