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-17 19:22:08 +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
|
2015-05-17 19:22:08 +03:00
|
|
|
, _stList :: List Int
|
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-16 08:03:53 +03:00
|
|
|
drawUI :: St -> [Prim]
|
|
|
|
drawUI st = [a]
|
2015-05-10 00:28:37 +03:00
|
|
|
where
|
2015-05-17 05:16:06 +03:00
|
|
|
a = centered $
|
|
|
|
bordered $
|
2015-05-17 19:22:08 +03:00
|
|
|
(VLimit 1 $
|
|
|
|
HLimit 25 $
|
|
|
|
UseAttr (cyan `on` blue) $
|
2015-05-17 19:46:17 +03:00
|
|
|
drawEditor (st^.stEditor))
|
2015-05-17 19:22:08 +03:00
|
|
|
<<=
|
|
|
|
HFill '-'
|
|
|
|
=>>
|
|
|
|
(VLimit 10 $
|
|
|
|
HLimit 25 $
|
2015-05-17 19:46:17 +03:00
|
|
|
drawList (st^.stList))
|
2015-05-09 09:09:40 +03:00
|
|
|
|
2015-05-17 19:41:17 +03:00
|
|
|
appEvent :: Event -> St -> IO St
|
|
|
|
appEvent e st =
|
2015-05-09 09:09:40 +03:00
|
|
|
case e of
|
2015-05-17 05:42:25 +03:00
|
|
|
EvKey KEsc [] -> exitSuccess
|
|
|
|
EvKey KEnter [] -> error $ editStr $ st^.stEditor
|
2015-05-17 19:41:17 +03:00
|
|
|
ev -> return $ st & stEditor %~ (handleEvent ev)
|
|
|
|
& stList %~ (handleEvent 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-17 19:46:17 +03:00
|
|
|
, _stList = list (Name "list") listDrawElem [0..6]
|
2015-05-09 19:14:56 +03:00
|
|
|
}
|
|
|
|
|
2015-05-17 19:44:18 +03:00
|
|
|
listDrawElem :: Bool -> Int -> Prim
|
|
|
|
listDrawElem sel i =
|
2015-05-17 19:22:08 +03:00
|
|
|
let selAttr = white `on` blue
|
2015-05-17 19:29:53 +03:00
|
|
|
p = hCentered (Txt $ "Number " <> show i)
|
2015-05-17 19:22:08 +03:00
|
|
|
in if sel
|
|
|
|
then UseAttr selAttr p
|
|
|
|
else p
|
|
|
|
|
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-17 19:41:17 +03:00
|
|
|
, appHandleEvent = appEvent
|
2015-05-17 18:17:06 +03:00
|
|
|
, appHandleSize =
|
2015-05-17 19:22:08 +03:00
|
|
|
\name sz st ->
|
|
|
|
case name of
|
|
|
|
Name "edit" -> st & stEditor %~ setSize sz
|
|
|
|
Name "list" -> st & stList %~ setSize sz
|
|
|
|
_ -> st
|
2015-05-09 19:24:59 +03:00
|
|
|
}
|
|
|
|
|
2015-05-09 09:09:40 +03:00
|
|
|
main :: IO ()
|
2015-05-11 01:51:08 +03:00
|
|
|
main = defaultMain theApp initialState
|