reflex-vty/src-bin/example.hs

59 lines
1.7 KiB
Haskell
Raw Normal View History

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
2018-09-01 19:02:15 +03:00
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
2018-09-01 19:02:15 +03:00
{-# LANGUAGE ScopedTypeVariables #-}
2018-10-14 03:28:02 +03:00
{-# OPTIONS_GHC -threaded #-}
2018-10-14 03:28:02 +03:00
import Control.Monad
2018-10-25 01:13:47 +03:00
import Control.Monad.Fix
import Control.Monad.IO.Class
2018-09-01 19:02:15 +03:00
import Control.Monad.Trans.Reader
import Data.Time
2018-10-14 03:28:02 +03:00
import qualified Graphics.Vty as V
import Reflex
import Reflex.Vty
import Reflex.Vty.Widget
main :: IO ()
2018-10-14 03:28:02 +03:00
main =
mainWidget $ do
2018-10-14 03:28:02 +03:00
inp <- input
tellShutdown . fforMaybe inp $ \case
V.EvKey V.KEsc _ -> Just ()
_ -> Nothing
2018-10-25 01:13:47 +03:00
debugInput
testBoxes
return ()
2018-10-14 03:28:02 +03:00
2018-10-25 01:13:47 +03:00
testBoxes :: (Reflex t, MonadHold t m, MonadFix m) => VtyWidget t m ()
testBoxes = do
size <- displaySize
let region1 = fmap (\(w,h) -> Region (w `div` 6) (h `div` 6) (w `div` 2) (h `div` 2)) size
region2 = fmap (\(w,h) -> Region (w `div` 4) (h `div` 4) (2 * (w `div` 3)) (2*(h `div` 3))) size
pane region1 (constDyn False) . box singleBoxStyle $ debugInput
pane region2 (constDyn True) . box singleBoxStyle $
splitVDrag (hRule doubleBoxStyle) (box roundedBoxStyle debugInput) (box roundedBoxStyle dragTest)
2018-10-25 01:13:47 +03:00
return ()
debugFocus :: (Reflex t, Monad m) => VtyWidget t m ()
debugFocus = do
f <- focus
string $ show <$> current f
2018-10-25 01:13:47 +03:00
debugInput :: (Reflex t, MonadHold t m) => VtyWidget t m ()
debugInput = do
lastEvent <- hold "No event yet" . fmap show =<< input
string lastEvent
2018-10-14 03:28:02 +03:00
2018-10-25 01:13:47 +03:00
dragTest :: (Reflex t, MonadHold t m, MonadFix m) => VtyWidget t m ()
dragTest = do
lastEvent <- hold "No event yet" . fmap show =<< drag V.BLeft
string lastEvent
2018-10-14 03:28:02 +03:00
testStringBox :: (Reflex t, Monad m) => VtyWidget t m ()
testStringBox = box singleBoxStyle .
string . pure . take 500 $ cycle ('\n' : ['a'..'z'])