on develop help sign in
Make tab width configurable
2f08cc7Ali Abrar
src/Reflex/Vty/Widget/Input/Text.hs+6−5
@@ -25,10 +25,11 @@ import Reflex.Vty.Widget
25data TextInputConfig t = TextInputConfig
25data TextInputConfig t = TextInputConfig
26 { _textInputConfig_initialValue :: TextZipper
26 { _textInputConfig_initialValue :: TextZipper
27 , _textInputConfig_modify :: Event t (TextZipper -> TextZipper)
27 , _textInputConfig_modify :: Event t (TextZipper -> TextZipper)
28+ , _textInputConfig_tabWidth :: Int
28 }
29 }
29
30
30instance Reflex t => Default (TextInputConfig t) where
31instance Reflex t => Default (TextInputConfig t) where
31− def = TextInputConfig empty never
32+ def = TextInputConfig empty never 4
32
33
33-- | A widget that allows text input
34-- | A widget that allows text input
34textInput
35textInput
@@ -39,7 +40,7 @@ textInput cfg = do
39 i <- input
40 i <- input
40 f <- focus
41 f <- focus
41 rec v <- foldDyn ($) (_textInputConfig_initialValue cfg) $ mergeWith (.)
42 rec v <- foldDyn ($) (_textInputConfig_initialValue cfg) $ mergeWith (.)
42− [ updateTextZipper <$> i
43+ [ updateTextZipper (_textInputConfig_tabWidth cfg) <$> i
43 , _textInputConfig_modify cfg
44 , _textInputConfig_modify cfg
44 , let displayInfo = (,) <$> rows <*> scrollTop
45 , let displayInfo = (,) <$> rows <*> scrollTop
45 in ffor (attach (current displayInfo) click) $ \((dl, st), MouseDown _ (mx, my) _) ->
46 in ffor (attach (current displayInfo) click) $ \((dl, st), MouseDown _ (mx, my) _) ->
@@ -95,10 +96,10 @@ spanToImage :: Span V.Attr -> V.Image
95spanToImage (Span attrs t) = V.text' attrs t
96spanToImage (Span attrs t) = V.text' attrs t
96
97
97-- | Default vty event handler for text inputs
98-- | Default vty event handler for text inputs
98−updateTextZipper :: V.Event -> TextZipper -> TextZipper
99+updateTextZipper :: Int -> V.Event -> TextZipper -> TextZipper
99−updateTextZipper ev = case ev of
100+updateTextZipper tabWidth ev = case ev of
100 -- Regular characters
101 -- Regular characters
101− V.EvKey (V.KChar '\t') [] -> tab 4
102+ V.EvKey (V.KChar '\t') [] -> tab tabWidth
102 V.EvKey (V.KChar k) [] -> insertChar k
103 V.EvKey (V.KChar k) [] -> insertChar k
103 -- Deletion buttons
104 -- Deletion buttons
104 V.EvKey V.KBS [] -> deleteLeft
105 V.EvKey V.KBS [] -> deleteLeft