on develop help sign in
TextInputConfig initial value
796086dAli Abrar
src/Reflex/Vty/Widget.hs+13−10
@@ -43,7 +43,7 @@ module Reflex.Vty.Widget
43 , doubleBoxStyle
43 , doubleBoxStyle
44 , fill
44 , fill
45 , hRule
45 , hRule
46−
46+ , TextInputConfig(..)
47 , textInput
47 , textInput
48 , multilineTextInput
48 , multilineTextInput
49 , def
49 , def
@@ -539,16 +539,17 @@ updateInputState ev i@(InputState before after) = case ev of
539 _ -> i
539 _ -> i
540
540
541data TextInputConfig t = TextInputConfig
541data TextInputConfig t = TextInputConfig
542+ { _textInputConfig_initialValue :: Text
542− { _textInputConfig_modifyInputState :: Event t (InputState -> InputState)
543+ , _textInputConfig_modifyInputState :: Event t (InputState -> InputState)
543 }
544 }
544
545
545instance Reflex t => Default (TextInputConfig t) where
546instance Reflex t => Default (TextInputConfig t) where
546− def = TextInputConfig never
547+ def = TextInputConfig "" never
547
548
548textInput :: (Reflex t, MonadHold t m, MonadFix m) => TextInputConfig t -> VtyWidget t m (Dynamic t Text)
549textInput :: (Reflex t, MonadHold t m, MonadFix m) => TextInputConfig t -> VtyWidget t m (Dynamic t Text)
549textInput cfg = do
550textInput cfg = do
550 i <- input
551 i <- input
551− v <- foldDyn ($) (InputState mempty mempty) $ mergeWith (.)
552+ v <- foldDyn ($) (InputState (_textInputConfig_initialValue cfg) mempty) $ mergeWith (.)
552 [ updateInputState <$> i
553 [ updateInputState <$> i
553 , _textInputConfig_modifyInputState cfg
554 , _textInputConfig_modifyInputState cfg
554 ]
555 ]
@@ -562,9 +563,11 @@ textInput cfg = do
562multilineTextInput :: (Reflex t, MonadHold t m, MonadFix m) => TextInputConfig t -> VtyWidget t m (Dynamic t Text)
563multilineTextInput :: (Reflex t, MonadHold t m, MonadFix m) => TextInputConfig t -> VtyWidget t m (Dynamic t Text)
563multilineTextInput cfg = do
564multilineTextInput cfg = do
564 i <- input
565 i <- input
565− textInput $ TextInputConfig $ mergeWith (.)
566+ textInput $ cfg
567+ { _textInputConfig_modifyInputState = mergeWith (.)
566− [ fforMaybe i $ \case
568+ [ fforMaybe i $ \case
567− V.EvKey V.KEnter [] -> Just $ \(InputState before after) -> InputState (T.snoc before '\n') after
569+ V.EvKey V.KEnter [] -> Just $ \(InputState before after) -> InputState (T.snoc before '\n') after
568− _ -> Nothing
570+ _ -> Nothing
569− , _textInputConfig_modifyInputState cfg
571+ , _textInputConfig_modifyInputState cfg
570− ]
572+ ]
573+ }