2015-05-09 09:09:40 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Main where
|
|
|
|
|
2015-05-09 19:56:14 +03:00
|
|
|
import Data.Default
|
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-10 00:37:27 +03:00
|
|
|
, trans :: Location
|
2015-05-09 10:45:46 +03:00
|
|
|
}
|
2015-05-09 10:18:29 +03:00
|
|
|
|
2015-05-09 19:14:56 +03:00
|
|
|
eName :: Name
|
|
|
|
eName = Name "edit"
|
|
|
|
|
2015-05-10 00:28:37 +03:00
|
|
|
drawUI :: St -> [Widget]
|
|
|
|
drawUI st = [top]
|
|
|
|
where
|
2015-05-10 00:37:27 +03:00
|
|
|
top = translated (trans st) $
|
|
|
|
hLimit 40 $
|
|
|
|
vBox [ "Top"
|
2015-05-10 00:28:37 +03:00
|
|
|
, hBorder '-'
|
|
|
|
, hBox [ " Edit: "
|
|
|
|
, hLimit 20 $ edit (stEditor st) `withAttr` (cyan `on` blue)
|
|
|
|
]
|
|
|
|
]
|
2015-05-09 09:09:40 +03:00
|
|
|
|
2015-05-09 20:11:36 +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-09 20:11:36 +03:00
|
|
|
EvKey KEsc [] -> exitSuccess
|
2015-05-09 20:20:31 +03:00
|
|
|
EvKey KEnter [] -> error $ editStr $ stEditor st
|
2015-05-10 00:37:27 +03:00
|
|
|
EvKey KLeft [MCtrl] -> return $ st { trans = trans st `locOffset` (Location (-1, 0)) }
|
|
|
|
EvKey KRight [MCtrl] -> return $ st { trans = trans st `locOffset` (Location (1, 0)) }
|
|
|
|
EvKey KUp [MCtrl] -> return $ st { trans = trans st `locOffset` (Location (0, -1)) }
|
|
|
|
EvKey KDown [MCtrl] -> return $ st { trans = trans st `locOffset` (Location (0, 1)) }
|
2015-05-09 20:11:36 +03:00
|
|
|
ev -> return $ st { stEditor = editEvent ev (stEditor st) }
|
2015-05-09 10:45:46 +03:00
|
|
|
|
|
|
|
initialState :: St
|
|
|
|
initialState =
|
2015-05-09 19:14:56 +03:00
|
|
|
St { focus = focusRing [eName]
|
|
|
|
, stEditor = editor eName ""
|
2015-05-10 00:37:27 +03:00
|
|
|
, trans = Location (0, 0)
|
2015-05-09 19:14:56 +03:00
|
|
|
}
|
|
|
|
|
2015-05-09 19:24:59 +03:00
|
|
|
app :: App St
|
|
|
|
app =
|
2015-05-09 19:56:14 +03:00
|
|
|
def { appDraw = drawUI
|
2015-05-09 19:24:59 +03:00
|
|
|
, appChooseCursor = focusRingCursor focus
|
|
|
|
, appHandleEvent = handleEvent
|
|
|
|
}
|
|
|
|
|
2015-05-09 09:09:40 +03:00
|
|
|
main :: IO ()
|
|
|
|
main = standardIOConfig
|
|
|
|
>>= mkVty
|
2015-05-09 19:24:59 +03:00
|
|
|
>>= runVty app initialState
|