mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-12-04 17:36:43 +03:00
Merge pull request #15 from eigengrau/space-leak
Address space leaks in renderFinal and str
This commit is contained in:
commit
e4ccca052c
@ -87,7 +87,8 @@ library
|
||||
contravariant,
|
||||
text,
|
||||
text-zipper >= 0.2.1,
|
||||
template-haskell
|
||||
template-haskell,
|
||||
deepseq >= 1.4 && < 1.5
|
||||
|
||||
executable brick-visibility-demo
|
||||
if !flag(demos)
|
||||
|
@ -78,6 +78,7 @@ import qualified Data.Function as DF
|
||||
import Data.List (sortBy, partition)
|
||||
import Control.Lens (Lens')
|
||||
import qualified Graphics.Vty as V
|
||||
import Control.DeepSeq
|
||||
|
||||
import Brick.Types
|
||||
import Brick.Types.Internal
|
||||
@ -125,10 +126,11 @@ str :: String -> Widget
|
||||
str s =
|
||||
Widget Fixed Fixed $ do
|
||||
c <- getContext
|
||||
let theLines = lines s
|
||||
let theLines = fixEmpty <$> (dropUnused . lines) s
|
||||
fixEmpty [] = " "
|
||||
fixEmpty l = l
|
||||
case fixEmpty <$> theLines of
|
||||
dropUnused l = take (availWidth c) <$> take (availHeight c) l
|
||||
case force theLines of
|
||||
[] -> return def
|
||||
[one] -> return $ def & imageL .~ (V.string (c^.attrL) one)
|
||||
multiple ->
|
||||
|
@ -1,3 +1,5 @@
|
||||
{-# LANGUAGE BangPatterns #-}
|
||||
|
||||
module Brick.Widgets.Internal
|
||||
( renderFinal
|
||||
, cropToContext
|
||||
@ -24,7 +26,7 @@ renderFinal :: AttrMap
|
||||
-> (RenderState, V.Picture, Maybe CursorLocation)
|
||||
renderFinal aMap layerRenders sz chooseCursor rs = (newRS, pic, theCursor)
|
||||
where
|
||||
(layerResults, newRS) = flip runState rs $ sequence $
|
||||
(layerResults, !newRS) = flip runState rs $ sequence $
|
||||
(\p -> runReaderT p ctx) <$>
|
||||
(render <$> cropToContext <$> layerRenders)
|
||||
ctx = Context def (fst sz) (snd sz) def aMap
|
||||
|
Loading…
Reference in New Issue
Block a user