2015-08-20 05:40:06 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2015-07-09 21:03:48 +03:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Control.Applicative
|
|
|
|
import Control.Monad (void)
|
|
|
|
import Data.Monoid
|
|
|
|
import Data.Default
|
2015-07-10 23:38:05 +03:00
|
|
|
import qualified Graphics.Vty as V
|
2015-07-09 21:03:48 +03:00
|
|
|
|
2015-07-10 23:38:05 +03:00
|
|
|
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
|
2015-08-20 05:40:06 +03:00
|
|
|
import Brick.Types
|
2015-07-10 23:38:05 +03:00
|
|
|
( Widget
|
2015-07-18 05:30:42 +03:00
|
|
|
, ViewportType(Horizontal, Vertical, Both)
|
2015-08-20 05:40:06 +03:00
|
|
|
)
|
|
|
|
import Brick.Widgets.Core
|
|
|
|
( hLimit
|
2015-07-10 23:38:05 +03:00
|
|
|
, vLimit
|
|
|
|
, hBox
|
|
|
|
, vBox
|
|
|
|
, viewport
|
|
|
|
, str
|
|
|
|
)
|
2015-07-09 21:03:48 +03:00
|
|
|
|
2015-07-10 23:38:05 +03:00
|
|
|
vp1Name :: T.Name
|
2015-07-09 21:03:48 +03:00
|
|
|
vp1Name = "demo1"
|
|
|
|
|
2015-07-10 23:38:05 +03:00
|
|
|
vp2Name :: T.Name
|
2015-07-09 21:03:48 +03:00
|
|
|
vp2Name = "demo2"
|
|
|
|
|
2015-07-18 05:30:42 +03:00
|
|
|
vp3Name :: T.Name
|
|
|
|
vp3Name = "demo3"
|
|
|
|
|
2015-07-09 21:03:48 +03:00
|
|
|
drawUi :: () -> [Widget]
|
|
|
|
drawUi = const [ui]
|
|
|
|
where
|
2015-07-18 05:30:42 +03:00
|
|
|
ui = C.center $ B.border $ hLimit 60 $ vLimit 21 $
|
|
|
|
vBox [ pair, B.hBorder, singleton ]
|
|
|
|
singleton = viewport vp3Name Both $
|
2015-08-20 05:40:06 +03:00
|
|
|
vBox $ str "Press ctrl-arrow keys to scroll this viewport horizontally and vertically."
|
2015-07-18 05:30:42 +03:00
|
|
|
: (str <$> [ "Line " <> show i | i <- [2..25::Int] ])
|
|
|
|
pair = hBox [ viewport vp1Name Vertical $
|
2015-08-20 05:40:06 +03:00
|
|
|
vBox $ str "Press up and down arrow keys" :
|
|
|
|
str "to scroll this viewport." :
|
2015-07-18 05:30:42 +03:00
|
|
|
(str <$> [ "Line " <> (show i) | i <- [3..50::Int] ])
|
|
|
|
, B.vBorder
|
2015-08-20 05:40:06 +03:00
|
|
|
, viewport vp2Name Horizontal $
|
|
|
|
str "Press left and right arrow keys to scroll this viewport."
|
2015-07-18 05:30:42 +03:00
|
|
|
]
|
2015-07-09 21:03:48 +03:00
|
|
|
|
2015-07-10 23:38:05 +03:00
|
|
|
vp1Scroll :: M.ViewportScroll
|
|
|
|
vp1Scroll = M.viewportScroll vp1Name
|
2015-07-09 21:03:48 +03:00
|
|
|
|
2015-07-10 23:38:05 +03:00
|
|
|
vp2Scroll :: M.ViewportScroll
|
|
|
|
vp2Scroll = M.viewportScroll vp2Name
|
2015-07-09 21:03:48 +03:00
|
|
|
|
2015-07-18 05:30:42 +03:00
|
|
|
vp3Scroll :: M.ViewportScroll
|
|
|
|
vp3Scroll = M.viewportScroll vp3Name
|
|
|
|
|
2015-08-20 05:48:55 +03:00
|
|
|
appEvent :: () -> V.Event -> T.EventM (T.Next ())
|
2015-07-18 05:30:42 +03:00
|
|
|
appEvent _ (V.EvKey V.KDown [V.MCtrl]) = M.vScrollBy vp3Scroll 1 >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KUp [V.MCtrl]) = M.vScrollBy vp3Scroll (-1) >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KRight [V.MCtrl]) = M.hScrollBy vp3Scroll 1 >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KLeft [V.MCtrl]) = M.hScrollBy vp3Scroll (-1) >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KDown []) = M.vScrollBy vp1Scroll 1 >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KUp []) = M.vScrollBy vp1Scroll (-1) >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KRight []) = M.hScrollBy vp2Scroll 1 >> M.continue ()
|
|
|
|
appEvent _ (V.EvKey V.KLeft []) = M.hScrollBy vp2Scroll (-1) >> M.continue ()
|
2015-07-10 23:38:05 +03:00
|
|
|
appEvent _ (V.EvKey V.KEsc []) = M.halt ()
|
|
|
|
appEvent _ _ = M.continue ()
|
2015-07-09 21:03:48 +03:00
|
|
|
|
2015-07-10 23:38:05 +03:00
|
|
|
app :: M.App () V.Event
|
2015-07-09 21:03:48 +03:00
|
|
|
app =
|
2015-07-10 23:38:05 +03:00
|
|
|
M.App { M.appDraw = drawUi
|
|
|
|
, M.appStartEvent = return
|
|
|
|
, M.appHandleEvent = appEvent
|
|
|
|
, M.appAttrMap = const def
|
2015-07-10 23:53:21 +03:00
|
|
|
, M.appLiftVtyEvent = id
|
2015-07-10 23:38:05 +03:00
|
|
|
, M.appChooseCursor = M.neverShowCursor
|
|
|
|
}
|
2015-07-09 21:03:48 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2015-07-10 23:38:05 +03:00
|
|
|
main = void $ M.defaultMain app ()
|