@@ -43,7 +43,7 @@ data TextInput t = TextInput
4343
4444-- | A widget that allows text input
4545textInput
46− :: (Reflex t, MonadHold t m, MonadFix m, HasInput t m, HasFocusReader t m, HasDisplayRegion t m, HasImageWriter t m, HasDisplayRegion t m)
46+ :: (Reflex t, MonadHold t m, MonadFix m, HasInput t m, HasFocusReader t m, HasTheme t m, HasDisplayRegion t m, HasImageWriter t m, HasDisplayRegion t m)
4747 => TextInputConfig t
4848 -> m (TextInput t)
4949textInput cfg = do
@@ -51,6 +51,8 @@ textInput cfg = do
5151 f <- focus
5252 dh <- displayHeight
5353 dw <- displayWidth
54+ bt <- theme
55+ attr0 <- sample bt
5456 rec v <- foldDyn ($) (_textInputConfig_initialValue cfg) $ mergeWith (.)
5557 [ uncurry (updateTextZipper (_textInputConfig_tabWidth cfg)) <$> attach (current dh) i
5658 , _textInputConfig_modify cfg
@@ -59,12 +61,20 @@ textInput cfg = do
5961 goToDisplayLinePosition mx (st + my) dl
6062 ]
6163 click <- mouseDown V.BLeft
62− let cursorAttrs = ffor f $ \x -> if x then cursorAttributes else V.defAttr
63− let rows = (\w s c -> displayLines w V.defAttr c s)
64+
65+ -- TODO reverseVideo is prob not what we want. Does not work with `darkTheme` in example.hs (cursor is dark rather than light bg)
66+ let toCursorAttrs attr = V.withStyle attr V.reverseVideo
67+ rowInputDyn = (,,)
6468 <$> dw
6569 <*> (mapZipper <$> _textInputConfig_display cfg <*> v)
66− <*> cursorAttrs
70+ <*> f
71+ toDisplayLines attr (w, s, x) =
72+ let c = if x then toCursorAttrs attr else attr
73+ in displayLines w attr c s
74+ attrDyn <- holdDyn attr0 $ pushAlways (\_ -> sample bt) (updated rowInputDyn)
75+ let rows = ffor2 attrDyn rowInputDyn toDisplayLines
6776 img = images . _displayLines_spans <$> rows
77+
6878 y <- holdUniqDyn $ _displayLines_cursorY <$> rows
6979 let newScrollTop :: Int -> (Int, Int) -> Int
7080 newScrollTop st (h, cursorY)
@@ -81,7 +91,7 @@ textInput cfg = do
8191
8292-- | A widget that allows multiline text input
8393multilineTextInput
84− :: (Reflex t, MonadHold t m, MonadFix m, HasInput t m, HasFocusReader t m, HasDisplayRegion t m, HasImageWriter t m)
94+ :: (Reflex t, MonadHold t m, MonadFix m, HasInput t m, HasFocusReader t m, HasTheme t m, HasDisplayRegion t m, HasImageWriter t m)
8595 => TextInputConfig t
8696 -> m (TextInput t)
8797multilineTextInput cfg = do
@@ -99,7 +109,7 @@ multilineTextInput cfg = do
99109-- the computed line count to greedily size the tile when vertically
100110-- oriented, and uses the fallback width when horizontally oriented.
101111textInputTile
102− :: (Monad m, Reflex t, MonadFix m, HasLayout t m, HasInput t m, HasFocus t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m)
112+ :: (Monad m, Reflex t, MonadFix m, HasLayout t m, HasInput t m, HasFocus t m, HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m, HasTheme t m)
103113 => m (TextInput t)
104114 -> Dynamic t Int
105115 -> m (TextInput t)
@@ -111,10 +121,6 @@ textInputTile txt width = do
111121 Orientation_Row -> width
112122 return t
113123
114−-- | Default attributes for the text cursor
115−cursorAttributes :: V.Attr
116−cursorAttributes = V.withStyle V.defAttr V.reverseVideo
117−
118124-- | Turn a set of display line rows into a list of images (one per line)
119125images :: [[Span V.Attr]] -> [V.Image]
120126images = map (V.horizCat . map spanToImage)