on develop help sign in
Merge branch 'develop' of github.com:reflex-frp/reflex-vty into develop

* 'develop' of github.com:reflex-frp/reflex-vty: Make textInput's character transformation function dynamic Allow TextZipper contents to be transformed before display

commitd4c554f05ced911484504750e1000df608ceb1b9 authorAli Abrar <aliabrar@gmail.com> dateSat 7 Sep 2019, 15:07 (7 years ago) parent993d079abab9c4
3 files changed+21−2
ChangeLog.md+4 src/Data/Text/Zipper.hs+9 src/Reflex/Vty/Widget/Input/Text.hs+8−2
ChangeLog.md+4
@@ -1,5 +1,9 @@
11# Revision history for reflex-vty
22
3+## 0.1.2.0
4+* Allow TextZipper contents to be tranformed before being displayed
5+* Fix bug in `row` orientation
6+
37## 0.1.1.1
48
59* Bump minimum version of reflex
src/Data/Text/Zipper.hs+9
@@ -45,6 +45,15 @@ data TextZipper = TextZipper
4545instance IsString TextZipper where
4646 fromString = fromText . T.pack
4747
48+-- | Map a replacement function over the characters in a 'TextZipper'
49+mapZipper :: (Char -> Char) -> TextZipper -> TextZipper
50+mapZipper f (TextZipper lb b a la) = TextZipper
51+ { _textZipper_linesBefore = fmap (T.map f) lb
52+ , _textZipper_before = T.map f b
53+ , _textZipper_after = T.map f a
54+ , _textZipper_linesAfter = fmap (T.map f) la
55+ }
56+
4857-- | Move the cursor left one character, if possible
4958left :: TextZipper -> TextZipper
5059left = leftN 1
src/Reflex/Vty/Widget/Input/Text.hs+8−2
@@ -30,10 +30,13 @@ data TextInputConfig t = TextInputConfig
3030 { _textInputConfig_initialValue :: TextZipper
3131 , _textInputConfig_modify :: Event t (TextZipper -> TextZipper)
3232 , _textInputConfig_tabWidth :: Int
33+ , _textInputConfig_display :: Dynamic t (Char -> Char)
34+ -- ^ Transform the characters in a text input before displaying them. This is useful, e.g., for
35+ -- masking characters when entering passwords.
3336 }
3437
3538instance Reflex t => Default (TextInputConfig t) where
36− def = TextInputConfig empty never 4
39+ def = TextInputConfig empty never 4 (pure id)
3740
3841-- | The output produced by text input widgets, including the text
3942-- value and the number of display lines (post-wrapping). Note that some
@@ -62,7 +65,10 @@ textInput cfg = do
6265 ]
6366 click <- mouseDown V.BLeft
6467 let cursorAttrs = ffor f $ \x -> if x then cursorAttributes else V.defAttr
65− let rows = (\w s c -> displayLines w V.defAttr c s) <$> dw <*> v <*> cursorAttrs
68+ let rows = (\w s c -> displayLines w V.defAttr c s)
69+ <$> dw
70+ <*> (mapZipper <$> _textInputConfig_display cfg <*> v)
71+ <*> cursorAttrs
6672 img = images . _displayLines_spans <$> rows
6773 y <- holdUniqDyn $ _displayLines_cursorY <$> rows
6874 let newScrollTop :: Int -> (Int, Int) -> Int