@@ -30,12 +30,12 @@ module Reflex.Vty.Widget
30 , modifyImages
30 , modifyImages
31 , tellImages
31 , tellImages
32 , tellShutdown
32 , tellShutdown
33− , wrapString
33+ , wrapText
35 , splitVDrag
35 , splitVDrag
36 , fractionSz
36 , fractionSz
39 , hyphenBoxStyle
39 , hyphenBoxStyle
40 , singleBoxStyle
40 , singleBoxStyle
41 , roundedBoxStyle
41 , roundedBoxStyle
@@ -417,25 +417,30 @@ box style child = do
418 in sides ++ if width > 1 && height > 1 then corners else []
418 in sides ++ if width > 1 && height > 1 then corners else []
420−string :: (Reflex t, Monad m) => Behavior t String -> VtyWidget t m ()
420+text :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m ()
421−string msg = do
421+text msg = do
422 dw <- displayWidth
422 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
424 tellImages img
424 tellImages img
426regionBlankImage :: Region -> Image
426regionBlankImage :: Region -> Image
427−regionBlankImage r@(Region _ _ width height) =
427+regionBlankImage r@(Region left top width height) =
428− withinImage r $ wrapString width V.defAttr $ replicate (width * height) ' '
428+ withinImage r $ V.charFill V.defAttr ' ' width height
430withinImage :: Region -> Image -> Image
430withinImage :: Region -> Image -> Image
431withinImage (Region left top width height)
431withinImage (Region left top width height)
432 | width < 0 || height < 0 = withinImage (Region left top 0 0)
432 | width < 0 || height < 0 = withinImage (Region left top 0 0)
433 | otherwise = V.translate left top . V.crop width height
433 | otherwise = V.translate left top . V.crop width height
435−wrapString :: Int -> Attr -> String -> Image
435+wrapText :: Int -> Attr -> Text -> Image
436−wrapString maxWidth attrs = V.vertCat
436+wrapText maxWidth attrs = V.vertCat
437+ . concatMap (fmap (V.string attrs . T.unpack) . wrapWithOffset maxWidth 0)
440+wrapWithOffset :: Int -> Int -> Text -> [Text]
441+wrapWithOffset maxWidth n xs =
442+ let (firstLine, rest) = T.splitAt (maxWidth - n) xs
437− . concatMap (fmap (V.string attrs) . fmap (take maxWidth) . takeWhile (not . null) . iterate (drop maxWidth))
443+ in firstLine : (fmap (T.take maxWidth) . takeWhile (not . T.null) . iterate (T.drop maxWidth) $ rest)
440wrapInputState
445wrapInputState
441 :: Int -- ^ Maximum line length
446 :: Int -- ^ Maximum line length
@@ -462,7 +467,7 @@ wrapInputState maxWidth attrs cursorAttrs (InputState before after) =
462 (midBeforeTop, midBefore') = fromMaybe ([], "") $ initLast $ wrap [midBefore]
467 (midBeforeTop, midBefore') = fromMaybe ([], "") $ initLast $ wrap [midBefore]
463 (midAfter', midAfterBottom) =
468 (midAfter', midAfterBottom) =
464 let offset = if T.length midBefore' == maxWidth then 1 else T.length midBefore' + 1
469 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
466 [] -> ("", [])
471 [] -> ("", [])
467 x:xs -> (x, xs)
472 x:xs -> (x, xs)
468 cursor = V.char cursorAttrs cursorChar
473 cursor = V.char cursorAttrs cursorChar
@@ -491,12 +496,8 @@ wrapInputState maxWidth attrs cursorAttrs (InputState before after) =
491 before' = T.split (=='\n') before
496 before' = T.split (=='\n') before
492 after' = T.split (=='\n') after
497 after' = T.split (=='\n') after
493 vstring = V.string attrs . T.unpack
498 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)
498 wrap :: [Text] -> [Text]
499 wrap :: [Text] -> [Text]
499− wrap = concatMap (wrapWithOffset 0)
500+ wrap = concatMap (wrapWithOffset maxWidth 0)
500 headTail :: [a] -> Maybe (a, [a])
501 headTail :: [a] -> Maybe (a, [a])
501 headTail = \case
502 headTail = \case
502 [] -> Nothing
503 [] -> Nothing