2015-05-09 09:09:40 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2015-05-11 17:55:48 +03:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2015-05-09 09:09:40 +03:00
|
|
|
module Main where
|
|
|
|
|
2015-05-11 17:55:48 +03:00
|
|
|
import Control.Lens
|
2015-05-09 19:56:14 +03:00
|
|
|
import Data.Default
|
2015-05-11 17:55:48 +03:00
|
|
|
import Data.Monoid
|
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-11 17:55:48 +03:00
|
|
|
St { _stEditor :: Editor
|
|
|
|
, _trans :: Location
|
2015-05-09 10:45:46 +03:00
|
|
|
}
|
2015-05-09 10:18:29 +03:00
|
|
|
|
2015-05-11 17:55:48 +03:00
|
|
|
makeLenses ''St
|
|
|
|
|
2015-05-10 00:28:37 +03:00
|
|
|
drawUI :: St -> [Widget]
|
|
|
|
drawUI st = [top]
|
|
|
|
where
|
2015-05-12 09:20:01 +03:00
|
|
|
top = liftVty $ mkImage (10, 10) defAttr $
|
|
|
|
borderTest $ Fixed "foo"
|
|
|
|
-- top = translated (st^.trans) $
|
|
|
|
-- bordered $
|
|
|
|
-- hLimit 40 $
|
|
|
|
-- vBox [ "Top"
|
|
|
|
-- , hBorder '-'
|
|
|
|
-- , hBox [ " Edit: "
|
|
|
|
-- , hLimit 20 $ edit (st^.stEditor) `withAttr` (cyan `on` blue)
|
|
|
|
-- ]
|
|
|
|
-- ]
|
2015-05-09 09:09:40 +03:00
|
|
|
|
2015-05-11 01:51:08 +03:00
|
|
|
handleEvent :: Event -> St -> IO St
|
2015-05-09 10:45:46 +03:00
|
|
|
handleEvent e st =
|
2015-05-09 09:09:40 +03:00
|
|
|
case e of
|
2015-05-11 17:55:48 +03:00
|
|
|
EvKey KEsc [] -> exitSuccess
|
|
|
|
EvKey KEnter [] -> error $ editStr $ st^.stEditor
|
|
|
|
EvKey KLeft [MCtrl] -> return $ st & trans %~ (<> (Location (-1, 0)))
|
|
|
|
EvKey KRight [MCtrl] -> return $ st & trans %~ (<> (Location (1, 0)))
|
|
|
|
EvKey KUp [MCtrl] -> return $ st & trans %~ (<> (Location (0, -1)))
|
|
|
|
EvKey KDown [MCtrl] -> return $ st & trans %~ (<> (Location (0, 1)))
|
|
|
|
ev -> return $ st & stEditor %~ (editEvent ev)
|
2015-05-09 10:45:46 +03:00
|
|
|
|
|
|
|
initialState :: St
|
|
|
|
initialState =
|
2015-05-11 19:56:11 +03:00
|
|
|
St { _stEditor = editor (Name "edit") ""
|
2015-05-11 17:55:48 +03:00
|
|
|
, _trans = Location (0, 0)
|
2015-05-09 19:14:56 +03:00
|
|
|
}
|
|
|
|
|
2015-05-11 01:51:08 +03:00
|
|
|
theApp :: App St Event
|
2015-05-11 00:56:58 +03:00
|
|
|
theApp =
|
2015-05-09 19:56:14 +03:00
|
|
|
def { appDraw = drawUI
|
2015-05-11 01:42:59 +03:00
|
|
|
, appChooseCursor = showFirstCursor
|
2015-05-09 19:24:59 +03:00
|
|
|
, appHandleEvent = handleEvent
|
|
|
|
}
|
|
|
|
|
2015-05-09 09:09:40 +03:00
|
|
|
main :: IO ()
|
2015-05-11 01:51:08 +03:00
|
|
|
main = defaultMain theApp initialState
|