-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTui.hs
65 lines (55 loc) · 1.6 KB
/
Tui.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Main where
import Brick.AttrMap
import Brick.Widgets.Border
import Brick.Main
import Brick.Types
import Brick.Widgets.Core
import Graphics.Vty.Input.Events
import Materials
import FiniteHexGrid
import InfiniteHexGrid
import System.Random (getStdGen,mkStdGen)
import Data.List (intersperse)
mat = fromID materialPacks "mono"
seed = 2022
data ResourceName =
ResourceName
deriving (Show, Eq, Ord)
tuiApp :: App (IHexGrid a) e ()
tuiApp =
App
{ appDraw = drawTui
, appChooseCursor = showFirstCursor
, appHandleEvent = handleTuiEvent
, appStartEvent = pure
, appAttrMap = const $ attrMap mempty []
}
buildInitialState :: (RealFrac a) => IHexGrid a
buildInitialState =
initIHexGrid gen (0, materialSpan)
where
materialSpan = length mat - 1
gen = mkStdGen seed
drawTui :: IHexGrid a -> [Widget ()]
drawTui grid =
[ borderWithLabel (str " [q]uit | wasd ") $
vBox $ (map str $ finiteHexGridZ viewPort grid)
]
where
viewPort = ViewPort (150, 150) (15,15) _zoom mat
_zoom = 2
handleTuiEvent :: IHexGrid a -> BrickEvent n e -> EventM n (Next (IHexGrid a))
handleTuiEvent state (VtyEvent vtye) =
case vtye of
EvKey (KChar 'q') [] -> halt state
EvKey (KChar 'w') [] -> continue (move North state)
EvKey (KChar 'a') [] -> continue (move West state)
EvKey (KChar 's') [] -> continue (move South state)
EvKey (KChar 'd') [] -> continue (move East state)
_ -> continue state
handleTuiEvent state _ = continue state
main :: IO ()
main = do
let initialState = buildInitialState
finalState <- defaultMain tuiApp initialState
return ()