2015-07-18 05:30:42 +03:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2018-03-17 19:03:30 +03:00
|
|
|
{-# LANGUAGE CPP #-}
|
2015-07-18 05:30:42 +03:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Control.Monad (void)
|
2016-05-09 04:05:30 +03:00
|
|
|
import Lens.Micro
|
|
|
|
import Lens.Micro.TH
|
2022-07-17 09:10:03 +03:00
|
|
|
import Lens.Micro.Mtl
|
2018-03-17 19:03:30 +03:00
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
2015-07-18 05:30:42 +03:00
|
|
|
import Data.Monoid
|
2018-03-17 19:03:30 +03:00
|
|
|
#endif
|
2015-07-18 05:30:42 +03:00
|
|
|
import qualified Graphics.Vty as V
|
|
|
|
|
|
|
|
import qualified Brick.Types as T
|
|
|
|
import qualified Brick.Main as M
|
|
|
|
import qualified Brick.Widgets.Center as C
|
|
|
|
import qualified Brick.Widgets.Border as B
|
2022-08-05 04:44:57 +03:00
|
|
|
import Brick.AttrMap (AttrMap, AttrName, attrMap, attrName)
|
2015-07-18 05:30:42 +03:00
|
|
|
import Brick.Util (on)
|
2015-08-20 05:40:06 +03:00
|
|
|
import Brick.Types
|
2015-07-18 05:30:42 +03:00
|
|
|
( Widget
|
|
|
|
, ViewportType(Horizontal, Vertical, Both)
|
2015-08-20 05:40:06 +03:00
|
|
|
)
|
|
|
|
import Brick.Widgets.Core
|
|
|
|
( withAttr
|
2015-07-18 05:30:42 +03:00
|
|
|
, hLimit
|
|
|
|
, vLimit
|
|
|
|
, hBox
|
|
|
|
, vBox
|
|
|
|
, viewport
|
|
|
|
, str
|
|
|
|
, visible
|
|
|
|
)
|
|
|
|
|
|
|
|
data St =
|
|
|
|
St { _vp1Index :: Int
|
|
|
|
, _vp2Index :: Int
|
|
|
|
, _vp3Index :: (Int, Int)
|
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''St
|
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
data Name = VP1
|
|
|
|
| VP2
|
|
|
|
| VP3
|
|
|
|
deriving (Show, Ord, Eq)
|
2015-07-18 05:30:42 +03:00
|
|
|
|
|
|
|
vp1Size :: Int
|
|
|
|
vp1Size = 15
|
|
|
|
|
|
|
|
vp2Size :: Int
|
|
|
|
vp2Size = 15
|
|
|
|
|
|
|
|
vp3Size :: (Int, Int)
|
|
|
|
vp3Size = (25, 25)
|
|
|
|
|
|
|
|
selectedAttr :: AttrName
|
2022-08-05 04:44:57 +03:00
|
|
|
selectedAttr = attrName "selected"
|
2015-07-18 05:30:42 +03:00
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
drawUi :: St -> [Widget Name]
|
2015-07-18 05:30:42 +03:00
|
|
|
drawUi st = [ui]
|
|
|
|
where
|
|
|
|
ui = C.center $ hLimit 60 $ vLimit 30 $
|
|
|
|
vBox [ B.border $ vBox [ pair, B.hBorder, singleton ]
|
2015-08-20 18:36:39 +03:00
|
|
|
, str $ "- Up/down arrow keys scroll the top-left viewport\n" <>
|
2015-07-18 05:30:42 +03:00
|
|
|
"- Left/right arrow keys scroll the top-right viewport\n" <>
|
|
|
|
"- Ctrl-arrow keys move the bottom viewport"
|
|
|
|
]
|
2016-03-05 01:42:49 +03:00
|
|
|
singleton = viewport VP3 Both $
|
2015-07-18 05:30:42 +03:00
|
|
|
vBox $ do
|
|
|
|
i <- [1..vp3Size^._1]
|
|
|
|
let row = do
|
|
|
|
j <- [1..vp3Size^._2]
|
|
|
|
let mkItem = if (i, j) == st^.vp3Index
|
|
|
|
then withAttr selectedAttr . visible
|
|
|
|
else id
|
|
|
|
return $ mkItem $ str $ "Item " <> show (i, j) <> " "
|
|
|
|
return $ hBox row
|
|
|
|
|
|
|
|
pair = hBox [ vp1, B.vBorder, vp2 ]
|
2016-03-05 01:42:49 +03:00
|
|
|
vp1 = viewport VP1 Vertical $
|
2015-07-18 05:30:42 +03:00
|
|
|
vBox $ do
|
|
|
|
i <- [1..vp1Size]
|
|
|
|
let mkItem = if i == st^.vp1Index
|
|
|
|
then withAttr selectedAttr . visible
|
|
|
|
else id
|
|
|
|
return $ mkItem $ str $ "Item " <> show i
|
2016-03-05 01:42:49 +03:00
|
|
|
vp2 = viewport VP2 Horizontal $
|
2015-07-18 05:30:42 +03:00
|
|
|
hBox $ do
|
|
|
|
i <- [1..vp2Size]
|
|
|
|
let mkItem = if i == st^.vp2Index
|
|
|
|
then withAttr selectedAttr . visible
|
|
|
|
else id
|
|
|
|
return $ mkItem $ str $ "Item " <> show i <> " "
|
|
|
|
|
2022-07-17 09:13:37 +03:00
|
|
|
vp1Scroll :: M.ViewportScroll Name
|
2016-03-05 01:42:49 +03:00
|
|
|
vp1Scroll = M.viewportScroll VP1
|
2015-07-18 05:30:42 +03:00
|
|
|
|
2022-07-17 09:13:37 +03:00
|
|
|
vp2Scroll :: M.ViewportScroll Name
|
2016-03-05 01:42:49 +03:00
|
|
|
vp2Scroll = M.viewportScroll VP2
|
2015-07-18 05:30:42 +03:00
|
|
|
|
2022-07-17 09:13:37 +03:00
|
|
|
vp3Scroll :: M.ViewportScroll Name
|
2016-03-05 01:42:49 +03:00
|
|
|
vp3Scroll = M.viewportScroll VP3
|
2015-07-18 05:30:42 +03:00
|
|
|
|
2022-07-17 09:10:03 +03:00
|
|
|
appEvent :: T.BrickEvent Name e -> T.EventM Name St ()
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KDown [V.MCtrl])) = vp3Index._1 %= min (vp3Size^._1) . (+ 1)
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KUp [V.MCtrl])) = vp3Index._1 %= max 1 . subtract 1
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KRight [V.MCtrl])) = vp3Index._2 %= min (vp3Size^._1) . (+ 1)
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KLeft [V.MCtrl])) = vp3Index._2 %= max 1 . subtract 1
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KDown [])) = vp1Index %= min vp1Size . (+ 1)
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KUp [])) = vp1Index %= max 1 . subtract 1
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KRight [])) = vp2Index %= min vp2Size . (+ 1)
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KLeft [])) = vp2Index %= max 1 . subtract 1
|
|
|
|
appEvent (T.VtyEvent (V.EvKey V.KEsc [])) = M.halt
|
|
|
|
appEvent _ = return ()
|
2015-07-18 05:30:42 +03:00
|
|
|
|
|
|
|
theMap :: AttrMap
|
|
|
|
theMap = attrMap V.defAttr
|
|
|
|
[ (selectedAttr, V.black `on` V.yellow)
|
|
|
|
]
|
|
|
|
|
2016-10-26 06:19:31 +03:00
|
|
|
app :: M.App St e Name
|
2015-07-18 05:30:42 +03:00
|
|
|
app =
|
|
|
|
M.App { M.appDraw = drawUi
|
2022-07-17 09:10:03 +03:00
|
|
|
, M.appStartEvent = return ()
|
2015-07-18 05:30:42 +03:00
|
|
|
, M.appHandleEvent = appEvent
|
|
|
|
, M.appAttrMap = const theMap
|
|
|
|
, M.appChooseCursor = M.neverShowCursor
|
|
|
|
}
|
|
|
|
|
|
|
|
initialState :: St
|
|
|
|
initialState = St 1 1 (1, 1)
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = void $ M.defaultMain app initialState
|