on master help sign in
Delay cursor clamping logic until logical positions are known
commit5e79d94786d0c0fd9f87a8d04f49410006ba3425 authorEric Mertens <emertens@gmail.com> dateThu 1 Sep 2016, 13:14 (10 years ago) parent5f6bb0f
2 files changed+13−26
src/Graphics/Vty.hs+5−23 src/Graphics/Vty/Output/Interface.hs+8−3
src/Graphics/Vty.hs+5−23
@@ -129,43 +129,25 @@ intMkVty input out = do
129129 lastUpdateRef <- newIORef Nothing
130130
131131 let innerUpdate inPic = do
132− b@(w,h) <- displayBounds out
132+ b <- displayBounds out
133133 let cursor = picCursor inPic
134− inPic' = case cursor of
135− AbsoluteCursor x y ->
136− let x' = max 0 (min (w-1) x)
137− y' = max 0 (min (h-1) y)
138− in inPic { picCursor = AbsoluteCursor x' y' }
139− -- TODO: account for logical width in Cursor case
140− Cursor x y ->
141− let
142− x' = case x of
143− _ | x < 0 -> 0
144− | x >= w -> w - 1
145− | otherwise -> x
146− y' = case y of
147− _ | y < 0 -> 0
148− | y >= h -> h - 1
149− | otherwise -> y
150− in inPic { picCursor = Cursor x' y' }
151− _ -> inPic
152134 mlastUpdate <- readIORef lastUpdateRef
153135 updateData <- case mlastUpdate of
154136 Nothing -> do
155137 dc <- displayContext out b
156− outputPicture dc inPic'
138+ outputPicture dc inPic
157139 return (b, dc)
158140 Just (lastBounds, lastContext) -> do
159141 if b /= lastBounds
160142 then do
161143 dc <- displayContext out b
162− outputPicture dc inPic'
144+ outputPicture dc inPic
163145 return (b, dc)
164146 else do
165− outputPicture lastContext inPic'
147+ outputPicture lastContext inPic
166148 return (b, lastContext)
167149 writeIORef lastUpdateRef $ Just updateData
168− writeIORef lastPicRef $ Just inPic'
150+ writeIORef lastPicRef $ Just inPic
169151
170152 let innerRefresh = do
171153 writeIORef lastUpdateRef Nothing
src/Graphics/Vty/Output/Interface.hs+8−3
@@ -166,15 +166,20 @@ outputPicture dc pic = liftIO $ do
166166 out = (if manipCursor then writeHideCursor dc else mempty)
167167 `mappend` writeOutputOps dc initialAttr diffs ops
168168 `mappend`
169− (case picCursor pic of
169+ (let (w,h) = contextRegion dc
170+ clampX = max 0 . min (w-1)
171+ clampY = max 0 . min (h-1) in
172+ case picCursor pic of
170173 _ | not manipCursor -> mempty
171174 NoCursor -> mempty
172175 AbsoluteCursor x y ->
173− writeShowCursor dc `mappend` writeMoveCursor dc x y
176+ writeShowCursor dc `mappend`
177+ writeMoveCursor dc (clampX x) (clampY y)
174178 Cursor x y ->
175179 let m = cursorOutputMap ops $ picCursor pic
176180 (ox, oy) = charToOutputPos m (x,y)
177− in writeShowCursor dc `mappend` writeMoveCursor dc ox oy
181+ in writeShowCursor dc `mappend`
182+ writeMoveCursor dc (clampX ox) (clampY oy)
178183 )
179184 -- ... then serialize
180185 outputByteBuffer (contextDevice dc) (writeToByteString out)