on develop help sign in
Add haddocks to several things
commit5ae2f4629fe86c030af41961f5432c4e686e46c5 authorAli Abrar <aliabrar@gmail.com> dateSun 4 Nov 2018, 02:35 (8 years ago) parent9c9a2ab
6 files changed+66−13
src/Data/Text/Zipper.hs+9 src/Reflex/Vty.hs+13 src/Reflex/Vty/Host.hs+9 src/Reflex/Vty/Widget.hs+27−13 src/Reflex/Vty/Widget/Input.hs+4 src/Reflex/Vty/Widget/Input/Text.hs+4
src/Data/Text/Zipper.hs+9
@@ -1,3 +1,12 @@
1+{-|
2+Module: Data.Text.Zipper
3+Description: A zipper for text documents that allows convenient editing and navigation
4+
5+'TextZipper' is designed to be help manipulate the contents of a text input field. It keeps track of the logical lines of text (i.e., lines separated by user-entered newlines) and the current cursor position. Several functions are defined in this module to navigate and edit the TextZipper from the cursor position.
6+
7+'TextZipper's can be converted into 'DisplayLines', which describe how the contents of the zipper will be displayed when wrapped to fit within a container of a certain width. It also provides some convenience facilities for converting interactions with the rendered DisplayLines back into manipulations of the underlying TextZipper.
8+
9+-}
110{-# LANGUAGE FlexibleContexts #-}
211{-# LANGUAGE LambdaCase #-}
312{-# LANGUAGE OverloadedStrings #-}
src/Reflex/Vty.hs+13
@@ -1,3 +1,16 @@
1+{-|
2+Module: Reflex.Vty
3+Description: A library for building vty apps with reflex
4+Copyright : (c) Obsidian Systems LLC
5+License : GPL-3
6+Maintainer : maintainer@obsidian.systems
7+Stability : experimental
8+Portability : POSIX
9+-}
10+
11+{-# LANGUAGE LambdaCase #-}
12+{-# LANGUAGE OverloadedStrings #-}
13+{-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
114module Reflex.Vty
215 ( module Reflex
316 , module Reflex.Vty.Host
src/Reflex/Vty/Host.hs+9
@@ -1,3 +1,7 @@
1+{-|
2+Module: Reflex.Vty.Host
3+Description: Scaffolding for running a reflex-vty application
4+-}
15{-# LANGUAGE FlexibleContexts #-}
26{-# LANGUAGE FlexibleInstances #-}
37{-# LANGUAGE LambdaCase #-}
@@ -40,6 +44,8 @@ import Reflex.Spider.Orphans ()
4044import qualified Graphics.Vty as V
4145import Graphics.Vty (DisplayRegion)
4246
47+-- | A synonym for the underlying vty event type from 'Graphics.Vty'. This should
48+-- probably ultimately be replaced by something defined in this library.
4349type VtyEvent = V.Event
4450
4551-- | The output of a 'VtyApp'.
@@ -51,6 +57,8 @@ data VtyResult t = VtyResult
5157 -- ^ An event that requests application termination.
5258 }
5359
60+-- | The constraints necessary to run a 'VtyApp'. See 'runVtyAppWithHandle' for more
61+-- on why each of these are necessary and how they can be fulfilled.
5462type MonadVtyApp t m =
5563 ( Reflex t
5664 , MonadHold t m
@@ -225,6 +233,7 @@ runVtyApp app = do
225233 vty <- getDefaultVty
226234 runVtyAppWithHandle vty app
227235
236+-- | Returns the standard vty configuration with mouse mode enabled.
228237getDefaultVty :: IO V.Vty
229238getDefaultVty = do
230239 cfg <- V.standardIOConfig
src/Reflex/Vty/Widget.hs+27−13
@@ -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')
src/Reflex/Vty/Widget/Input.hs+4
@@ -1,3 +1,7 @@
1+{-|
2+Module: Reflex.Vty.Widget.Input
3+Description: User input widgets for reflex-vty
4+-}
15module Reflex.Vty.Widget.Input
26 ( module Reflex.Vty.Widget.Input.Text
37 ) where
src/Reflex/Vty/Widget/Input/Text.hs+4
@@ -1,3 +1,7 @@
1+{-|
2+Module: Reflex.Vty.Widget.Input.Text
3+Description: Widgets for accepting text input from users and manipulating text within those inputs
4+-}
15{-# LANGUAGE FlexibleContexts #-}
26{-# LANGUAGE LambdaCase #-}
37{-# LANGUAGE OverloadedStrings #-}