module Main where

import Control.Monad ( forM_ )
import Widgets

import Graphics.Vty

titleAttr :: Attr
titleAttr = def_attr
            `with_back_color` blue
            `with_fore_color` bright_white

bodyAttr :: Attr
bodyAttr = def_attr
           `with_back_color` black
           `with_fore_color` bright_green

mainWidget :: VBox
mainWidget =
    let title = Text titleAttr " Title "
        body = Text bodyAttr "Body"
        footer = Text titleAttr " Footer"
        fill = vFill bodyAttr ' '
    in VBox title
           (VBox
            (VBox body fill)
            footer
           )

testVbox :: VBox
testVbox =
    let top = VBox (Text titleAttr "First") (vFill bodyAttr ' ')
        bottom = VBox (Text titleAttr "Third") (vFill bodyAttr ' ')
        footer = Text titleAttr "Footer"
    in VBox (VBox top bottom) footer

testWidgets :: [AnyWidget]
testWidgets = [ AnyWidget mainWidget
              , AnyWidget testVbox
              ]

main :: IO ()
main = do
  vty <- mkVty

  forM_ testWidgets $ \w -> do
         img <- mkImage vty w
         update vty $ pic_for_image img
         next_event vty

  shutdown vty

module Main where

import Control.Applicative ( (<$>) )
import Control.Monad ( forM_ )
import Widgets

import Graphics.Vty

titleAttr :: Attr
titleAttr = def_attr
            `with_back_color` blue
            `with_fore_color` bright_white

bodyAttr :: Attr
bodyAttr = def_attr
           `with_back_color` black
           `with_fore_color` bright_green

mainWidget :: VBox
mainWidget =
    let title = Text titleAttr " Title "
        body = Text bodyAttr "Body"
        footer = Text titleAttr " Footer"
        fill = vFill bodyAttr ' '
    in VBox title
           (VBox
            (VBox body fill)
            footer
           )

testVbox :: VBox
testVbox =
    let top = VBox (Text titleAttr "First") (vFill bodyAttr ' ')
        bottom = VBox (Text titleAttr "Third") (vFill bodyAttr ' ')
        footer = Text titleAttr "Footer"
    in VBox (VBox top bottom) footer

testWidgets :: [AnyWidget]
testWidgets = [ AnyWidget mainWidget
              , AnyWidget testVbox
              ]

main :: IO ()
main = do
  vty <- mkVty

  forM_ testWidgets $ \w -> do
         pic_for_image <$> mkImage vty w >>= update vty
         next_event vty

  shutdown vty

Use applicative style in widget test loop
Use applicative style in widget test loop

Ignore-this: 8b9e6fbd52ccbe2c3fe307b3e35d8cb7

darcs-hash:20090927210224-e018d-733ff1a483e7042dd4c1b44e35447440d57039d5.gz
