@@ -30,12 +30,12 @@ module Reflex.Vty.Widget
3030 , modifyImages
3131 , tellImages
3232 , tellShutdown
33− , wrapString
33+ , wrapText
3434 , splitV
3535 , splitVDrag
3636 , fractionSz
3737 , box
38− , string
38+ , text
3939 , hyphenBoxStyle
4040 , singleBoxStyle
4141 , roundedBoxStyle
@@ -417,25 +417,30 @@ box style child = do
417417 ]
418418 in sides ++ if width > 1 && height > 1 then corners else []
419419
420−string :: (Reflex t, Monad m) => Behavior t String -> VtyWidget t m ()
421−string msg = do
420+text :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m ()
421+text msg = do
422422 dw <- displayWidth
423− let img = (\w s -> [wrapString w V.defAttr s]) <$> current dw <*> msg
423+ let img = (\w s -> [wrapText w V.defAttr s]) <$> current dw <*> msg
424424 tellImages img
425425
426426regionBlankImage :: Region -> Image
427−regionBlankImage r@(Region _ _ width height) =
428− withinImage r $ wrapString width V.defAttr $ replicate (width * height) ' '
427+regionBlankImage r@(Region left top width height) =
428+ withinImage r $ V.charFill V.defAttr ' ' width height
429429
430430withinImage :: Region -> Image -> Image
431431withinImage (Region left top width height)
432432 | width < 0 || height < 0 = withinImage (Region left top 0 0)
433433 | otherwise = V.translate left top . V.crop width height
434434
435−wrapString :: Int -> Attr -> String -> Image
436−wrapString maxWidth attrs = V.vertCat
437− . concatMap (fmap (V.string attrs) . fmap (take maxWidth) . takeWhile (not . null) . iterate (drop maxWidth))
438− . lines
435+wrapText :: Int -> Attr -> Text -> Image
436+wrapText maxWidth attrs = V.vertCat
437+ . concatMap (fmap (V.string attrs . T.unpack) . wrapWithOffset maxWidth 0)
438+ . T.split (=='\n')
439+
440+wrapWithOffset :: Int -> Int -> Text -> [Text]
441+wrapWithOffset maxWidth n xs =
442+ let (firstLine, rest) = T.splitAt (maxWidth - n) xs
443+ in firstLine : (fmap (T.take maxWidth) . takeWhile (not . T.null) . iterate (T.drop maxWidth) $ rest)
439444
440445wrapInputState
441446 :: Int -- ^ Maximum line length
@@ -462,7 +467,7 @@ wrapInputState maxWidth attrs cursorAttrs (InputState before after) =
462467 (midBeforeTop, midBefore') = fromMaybe ([], "") $ initLast $ wrap [midBefore]
463468 (midAfter', midAfterBottom) =
464469 let offset = if T.length midBefore' == maxWidth then 1 else T.length midBefore' + 1
465− in case wrapWithOffset offset midAfter of
470+ in case wrapWithOffset maxWidth offset midAfter of
466471 [] -> ("", [])
467472 x:xs -> (x, xs)
468473 cursor = V.char cursorAttrs cursorChar
@@ -491,12 +496,8 @@ wrapInputState maxWidth attrs cursorAttrs (InputState before after) =
491496 before' = T.split (=='\n') before
492497 after' = T.split (=='\n') after
493498 vstring = V.string attrs . T.unpack
494− wrapWithOffset :: Int -> Text -> [Text]
495− wrapWithOffset n xs =
496− let (firstLine, rest) = T.splitAt (maxWidth - n) xs
497− in firstLine : (fmap (T.take maxWidth) . takeWhile (not . T.null) . iterate (T.drop maxWidth) $ rest)
498499 wrap :: [Text] -> [Text]
499− wrap = concatMap (wrapWithOffset 0)
500+ wrap = concatMap (wrapWithOffset maxWidth 0)
500501 headTail :: [a] -> Maybe (a, [a])
501502 headTail = \case
502503 [] -> Nothing