Created
January 27, 2015 11:28
-
-
Save sordina/036628ef912b1e6f46dc to your computer and use it in GitHub Desktop.
Simple demo of VTY-UI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Text as T | |
import Graphics.Vty.Widgets.All | |
import Graphics.Vty.Input.Events | |
import Control.Monad | |
import Data.IORef | |
import System.Exit | |
import Control.Concurrent | |
type SubscriptionChan = Chan Int | |
type ListChan = Chan Int | |
main :: IO () | |
main = do | |
subscriptions <- newChan | |
lists <- newChan | |
forkIO $ randomResponse subscriptions lists | |
vtyApp subscriptions lists | |
randomResponse :: SubscriptionChan -> ListChan -> IO () | |
randomResponse subscriptions lists = do | |
return () | |
vtyApp :: SubscriptionChan -> ListChan -> IO () | |
vtyApp subscriptions lists = do | |
l1 <- newTextList ["hello", "world"] 1 | |
l2 <- newList 1 | |
focus <- newFocusGroup | |
h <- return l1 <++> vBorder <++> return l2 | |
coll <- newCollection | |
addToCollection coll h focus | |
addToFocusGroup focus l1 | |
addToFocusGroup focus l2 | |
addToList l2 'x' =<< plainText "cats" | |
addToList l2 'y' =<< plainText "and" | |
addToList l2 'z' =<< plainText "boots" | |
onKeyPressed focus $ \w k m -> | |
case (k,m) of (KChar 'c', [MCtrl]) -> exitSuccess | |
(KChar 'q', _ ) -> exitSuccess | |
(KChar 'j', _ ) -> scrollDown l1 >> return True | |
(KChar 'k', _ ) -> scrollUp l1 >> return True | |
_ -> return False | |
onItemActivated l1 activeItemHandler | |
onItemActivated l2 activeItemHandler | |
runUi coll defaultContext | |
activeItemHandler (ActivateItemEvent i a w) = print (i,a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment