on develop help sign in
Add haddocks to several things
5ae2f46Ali Abrar
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+-}
1{-# LANGUAGE FlexibleContexts #-}
10{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE LambdaCase #-}
11{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
12{-# 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 #-}
1module Reflex.Vty
14module Reflex.Vty
2 ( module Reflex
15 ( module Reflex
3 , module Reflex.Vty.Host
16 , 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+-}
1{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE LambdaCase #-}
7{-# LANGUAGE LambdaCase #-}
@@ -40,6 +44,8 @@ import Reflex.Spider.Orphans ()
40import qualified Graphics.Vty as V
44import qualified Graphics.Vty as V
41import Graphics.Vty (DisplayRegion)
45import Graphics.Vty (DisplayRegion)
42
46
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.
43type VtyEvent = V.Event
49type VtyEvent = V.Event
44
50
45-- | The output of a 'VtyApp'.
51-- | The output of a 'VtyApp'.
@@ -51,6 +57,8 @@ data VtyResult t = VtyResult
51 -- ^ An event that requests application termination.
57 -- ^ An event that requests application termination.
52 }
58 }
53
59
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.
54type MonadVtyApp t m =
62type MonadVtyApp t m =
55 ( Reflex t
63 ( Reflex t
56 , MonadHold t m
64 , MonadHold t m
@@ -225,6 +233,7 @@ runVtyApp app = do
225 vty <- getDefaultVty
233 vty <- getDefaultVty
226 runVtyAppWithHandle vty app
234 runVtyAppWithHandle vty app
227
235
236+-- | Returns the standard vty configuration with mouse mode enabled.
228getDefaultVty :: IO V.Vty
237getDefaultVty :: IO V.Vty
229getDefaultVty = do
238getDefaultVty = do
230 cfg <- V.standardIOConfig
239 cfg <- V.standardIOConfig
src/Reflex/Vty/Widget.hs+27−13
@@ -30,7 +30,6 @@ module Reflex.Vty.Widget
30 , modifyImages
30 , modifyImages
31 , tellImages
31 , tellImages
32 , tellShutdown
32 , tellShutdown
33− , wrapText
34 , splitV
33 , splitV
35 , splitVDrag
34 , splitVDrag
36 , fractionSz
35 , fractionSz
@@ -92,7 +91,9 @@ instance (Reflex t) => Monoid (VtyWidgetOut t) where
92 mempty = VtyWidgetOut mempty mempty
91 mempty = VtyWidgetOut mempty mempty
93 mappend wo wo' = wo <> wo'
92 mappend wo wo' = wo <> wo'
94
93
94+newtype VtyWidget t m a = VtyWidget
95−newtype VtyWidget t m a = VtyWidget { unVtyWidget :: WriterT (VtyWidgetOut t) (ReaderT (VtyWidgetCtx t) m) a }
95+ { unVtyWidget :: WriterT (VtyWidgetOut t) (ReaderT (VtyWidgetCtx t) m) a
96+ }
96 deriving (Functor, Applicative, Monad, MonadSample t, MonadHold t, MonadFix)
97 deriving (Functor, Applicative, Monad, MonadSample t, MonadHold t, MonadFix)
97
98
98-- | Runs a 'VtyWidget' with a given context
99-- | Runs a 'VtyWidget' with a given context
@@ -104,7 +105,10 @@ runVtyWidget
104runVtyWidget ctx w = runReaderT (runWriterT (unVtyWidget w)) ctx
105runVtyWidget ctx w = runReaderT (runWriterT (unVtyWidget w)) ctx
105
106
106-- | Sets up the top-level context for a 'VtyWidget' and runs it with that context
107-- | Sets up the top-level context for a 'VtyWidget' and runs it with that context
108+mainWidgetWithHandle
109+ :: V.Vty
107−mainWidgetWithHandle :: V.Vty -> (forall t m. MonadVtyApp t m => VtyWidget t m ()) -> IO ()
110+ -> (forall t m. MonadVtyApp t m => VtyWidget t m ())
111+ -> IO ()
108mainWidgetWithHandle vty child =
112mainWidgetWithHandle vty child =
109 runVtyAppWithHandle vty $ \dr0 inp -> do
113 runVtyAppWithHandle vty $ \dr0 inp -> do
110 size <- holdDyn dr0 $ fforMaybe inp $ \case
114 size <- holdDyn dr0 $ fforMaybe inp $ \case
@@ -125,7 +129,9 @@ mainWidgetWithHandle vty child =
125 }
129 }
126
130
127-- | Like 'mainWidgetWithHandle', but uses a default vty configuration
131-- | Like 'mainWidgetWithHandle', but uses a default vty configuration
132+mainWidget
128−mainWidget :: (forall t m. MonadVtyApp t m => VtyWidget t m ()) -> IO ()
133+ :: (forall t m. MonadVtyApp t m => VtyWidget t m ())
134+ -> IO ()
129mainWidget child = do
135mainWidget child = do
130 vty <- getDefaultVty
136 vty <- getDefaultVty
131 mainWidgetWithHandle vty child
137 mainWidgetWithHandle vty child
@@ -414,25 +420,33 @@ box style child = do
414 ]
420 ]
415 in sides ++ if width > 1 && height > 1 then corners else []
421 in sides ++ if width > 1 && height > 1 then corners else []
416
422
423+text
417−text :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m ()
424+ :: (Reflex t, Monad m)
425+ => Behavior t Text
426+ -> VtyWidget t m ()
418text msg = do
427text msg = do
419 dw <- displayWidth
428 dw <- displayWidth
420 let img = (\w s -> [wrapText w V.defAttr s]) <$> current dw <*> msg
429 let img = (\w s -> [wrapText w V.defAttr s]) <$> current dw <*> msg
421 tellImages img
430 tellImages img
422−
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
423−display :: (Reflex t, Monad m, Show a) => Behavior t a -> VtyWidget t m ()
437+ :: (Reflex t, Monad m, Show a)
438+ => Behavior t a
439+ -> VtyWidget t m ()
424display a = text $ T.pack . show <$> a
440display a = text $ T.pack . show <$> a
425
441
426regionBlankImage :: Region -> Image
442regionBlankImage :: Region -> Image
427regionBlankImage r@(Region _ _ width height) =
443regionBlankImage r@(Region _ _ width height) =
428 withinImage r $ V.charFill V.defAttr ' ' width height
444 withinImage r $ V.charFill V.defAttr ' ' width height
429
445
430−withinImage :: Region -> Image -> Image
446+withinImage
447+ :: Region
448+ -> Image
449+ -> Image
431withinImage (Region left top width height)
450withinImage (Region left top width height)
432 | width < 0 || height < 0 = withinImage (Region left top 0 0)
451 | width < 0 || height < 0 = withinImage (Region left top 0 0)
433 | otherwise = V.translate left top . V.crop width height
452 | 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+-}
1module Reflex.Vty.Widget.Input
5module Reflex.Vty.Widget.Input
2 ( module Reflex.Vty.Widget.Input.Text
6 ( module Reflex.Vty.Widget.Input.Text
3 ) where
7 ) 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+-}
1{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE LambdaCase #-}
6{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}