on develop help sign in
Allow TextZipper contents to be transformed before display
9305b01Ali Abrar
ChangeLog.md+4
@@ -1,5 +1,9 @@
1# Revision history for reflex-vty
1# Revision history for reflex-vty
2
2
3+## 0.1.2.0
4+* Allow TextZipper contents to be tranformed before being displayed
5+* Fix bug in `row` orientation
6+
3## 0.1.1.1
7## 0.1.1.1
4
8
5* Bump minimum version of reflex
9* Bump minimum version of reflex
src/Data/Text/Zipper.hs+9
@@ -39,6 +39,15 @@ data TextZipper = TextZipper
39instance IsString TextZipper where
39instance IsString TextZipper where
40 fromString = fromText . T.pack
40 fromString = fromText . T.pack
41
41
42+-- | Map a replacement function over the characters in a 'TextZipper'
43+mapZipper :: (Char -> Char) -> TextZipper -> TextZipper
44+mapZipper f (TextZipper lb b a la) = TextZipper
45+ { _textZipper_linesBefore = fmap (T.map f) lb
46+ , _textZipper_before = T.map f b
47+ , _textZipper_after = T.map f a
48+ , _textZipper_linesAfter = fmap (T.map f) la
49+ }
50+
42-- | Move the cursor left one character, if possible
51-- | Move the cursor left one character, if possible
43left :: TextZipper -> TextZipper
52left :: TextZipper -> TextZipper
44left = leftN 1
53left = leftN 1
src/Reflex/Vty/Widget/Input/Text.hs+8−2
@@ -30,10 +30,13 @@ data TextInputConfig t = TextInputConfig
30 { _textInputConfig_initialValue :: TextZipper
30 { _textInputConfig_initialValue :: TextZipper
31 , _textInputConfig_modify :: Event t (TextZipper -> TextZipper)
31 , _textInputConfig_modify :: Event t (TextZipper -> TextZipper)
32 , _textInputConfig_tabWidth :: Int
32 , _textInputConfig_tabWidth :: Int
33+ , _textInputConfig_display :: 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.
33 }
36 }
34
37
35instance Reflex t => Default (TextInputConfig t) where
38instance Reflex t => Default (TextInputConfig t) where
36− def = TextInputConfig empty never 4
39+ def = TextInputConfig empty never 4 id
37
40
38-- | The output produced by text input widgets, including the text
41-- | The output produced by text input widgets, including the text
39-- value and the number of display lines (post-wrapping). Note that some
42-- value and the number of display lines (post-wrapping). Note that some
@@ -62,7 +65,10 @@ textInput cfg = do
62 ]
65 ]
63 click <- mouseDown V.BLeft
66 click <- mouseDown V.BLeft
64 let cursorAttrs = ffor f $ \x -> if x then cursorAttributes else V.defAttr
67 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
66 img = images . _displayLines_spans <$> rows
72 img = images . _displayLines_spans <$> rows
67 y <- holdUniqDyn $ _displayLines_cursorY <$> rows
73 y <- holdUniqDyn $ _displayLines_cursorY <$> rows
68 let newScrollTop :: Int -> (Int, Int) -> Int
74 let newScrollTop :: Int -> (Int, Int) -> Int