@@ -30,7 +30,6 @@ module Reflex.Vty.Widget
3030 , modifyImages
3131 , tellImages
3232 , tellShutdown
33− , wrapText
3433 , splitV
3534 , splitVDrag
3635 , fractionSz
@@ -92,7 +91,9 @@ instance (Reflex t) => Monoid (VtyWidgetOut t) where
9291 mempty = VtyWidgetOut mempty mempty
9392 mappend wo wo' = wo <> wo'
9493
95−newtype VtyWidget t m a = VtyWidget { unVtyWidget :: WriterT (VtyWidgetOut t) (ReaderT (VtyWidgetCtx t) m) a }
94+newtype VtyWidget t m a = VtyWidget
95+ { unVtyWidget :: WriterT (VtyWidgetOut t) (ReaderT (VtyWidgetCtx t) m) a
96+ }
9697 deriving (Functor, Applicative, Monad, MonadSample t, MonadHold t, MonadFix)
9798
9899-- | Runs a 'VtyWidget' with a given context
@@ -104,7 +105,10 @@ runVtyWidget
104105runVtyWidget ctx w = runReaderT (runWriterT (unVtyWidget w)) ctx
105106
106107-- | Sets up the top-level context for a 'VtyWidget' and runs it with that context
107−mainWidgetWithHandle :: V.Vty -> (forall t m. MonadVtyApp t m => VtyWidget t m ()) -> IO ()
108+mainWidgetWithHandle
109+ :: V.Vty
110+ -> (forall t m. MonadVtyApp t m => VtyWidget t m ())
111+ -> IO ()
108112mainWidgetWithHandle vty child =
109113 runVtyAppWithHandle vty $ \dr0 inp -> do
110114 size <- holdDyn dr0 $ fforMaybe inp $ \case
@@ -125,7 +129,9 @@ mainWidgetWithHandle vty child =
125129 }
126130
127131-- | Like 'mainWidgetWithHandle', but uses a default vty configuration
128−mainWidget :: (forall t m. MonadVtyApp t m => VtyWidget t m ()) -> IO ()
132+mainWidget
133+ :: (forall t m. MonadVtyApp t m => VtyWidget t m ())
134+ -> IO ()
129135mainWidget child = do
130136 vty <- getDefaultVty
131137 mainWidgetWithHandle vty child
@@ -414,25 +420,33 @@ box style child = do
414420 ]
415421 in sides ++ if width > 1 && height > 1 then corners else []
416422
417−text :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m ()
423+text
424+ :: (Reflex t, Monad m)
425+ => Behavior t Text
426+ -> VtyWidget t m ()
418427text msg = do
419428 dw <- displayWidth
420429 let img = (\w s -> [wrapText w V.defAttr s]) <$> current dw <*> msg
421430 tellImages img
422−
423−display :: (Reflex t, Monad m, Show a) => Behavior t a -> VtyWidget t m ()
431+ where
432+ wrapText maxWidth attrs = V.vertCat
433+ . concatMap (fmap (V.string attrs . T.unpack) . TZ.wrapWithOffset maxWidth 0)
434+ . T.split (=='\n')
435+
436+display
437+ :: (Reflex t, Monad m, Show a)
438+ => Behavior t a
439+ -> VtyWidget t m ()
424440display a = text $ T.pack . show <$> a
425441
426442regionBlankImage :: Region -> Image
427443regionBlankImage r@(Region _ _ width height) =
428444 withinImage r $ V.charFill V.defAttr ' ' width height
429445
430−withinImage :: Region -> Image -> Image
446+withinImage
447+ :: Region
448+ -> Image
449+ -> Image
431450withinImage (Region left top width height)
432451 | width < 0 || height < 0 = withinImage (Region left top 0 0)
433452 | otherwise = V.translate left top . V.crop width height
434−
435−wrapText :: Int -> Attr -> Text -> Image
436−wrapText maxWidth attrs = V.vertCat
437− . concatMap (fmap (V.string attrs . T.unpack) . TZ.wrapWithOffset maxWidth 0)
438− . T.split (=='\n')