on master help sign in
Merge pull request #108 from glguy/absolute-cursor-patch

Add support for absolute cursor positioning

commit3c43f139e56068fe7095327dfe7e1fb0fad3cf01 authorJonathan Daugherty <cygnus@foobox.com> dateThu 1 Sep 2016, 22:47 (10 years ago) parentc264df94a8677c
7 files changed+34−33
CHANGELOG+3 src/Graphics/Vty.hs+5−18 src/Graphics/Vty/Config.hs+1−1 src/Graphics/Vty/Image/Internal.hs+5−4 src/Graphics/Vty/Output/Interface.hs+10−3 src/Graphics/Vty/Picture.hs+9−6 vty.cabal+1−1
CHANGELOG+3
@@ -1,3 +1,6 @@
1+5.10
2+ - Add aboslute cursor positioning mode AbsoluteCursor to Cursor
3+
145.9.1
25 - Vty now only emits UTF8 charset sequences in terminals without a
36 preexisting UTF8 declaration to avoid emitting garbage sequences
src/Graphics/Vty.hs+5−18
@@ -129,38 +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− Cursor x y ->
136− let
137− x' = case x of
138− _ | x < 0 -> 0
139− | x >= w -> w - 1
140− | otherwise -> x
141− y' = case y of
142− _ | y < 0 -> 0
143− | y >= h -> h - 1
144− | otherwise -> y
145− in inPic { picCursor = Cursor x' y' }
146− _ -> inPic
147134 mlastUpdate <- readIORef lastUpdateRef
148135 updateData <- case mlastUpdate of
149136 Nothing -> do
150137 dc <- displayContext out b
151− outputPicture dc inPic'
138+ outputPicture dc inPic
152139 return (b, dc)
153140 Just (lastBounds, lastContext) -> do
154141 if b /= lastBounds
155142 then do
156143 dc <- displayContext out b
157− outputPicture dc inPic'
144+ outputPicture dc inPic
158145 return (b, dc)
159146 else do
160− outputPicture lastContext inPic'
147+ outputPicture lastContext inPic
161148 return (b, lastContext)
162149 writeIORef lastUpdateRef $ Just updateData
163− writeIORef lastPicRef $ Just inPic'
150+ writeIORef lastPicRef $ Just inPic
164151
165152 let innerRefresh = do
166153 writeIORef lastUpdateRef Nothing
src/Graphics/Vty/Config.hs+1−1
@@ -266,7 +266,7 @@ parseModifier :: forall s u (m :: * -> *).
266266parseModifier = do
267267 m <- P.identifier configLexer
268268 case m of
269− "KMenu" -> return MShift
269+ "MShift" -> return MShift
270270 "MCtrl" -> return MCtrl
271271 "MMeta" -> return MMeta
272272 "MAlt" -> return MAlt
src/Graphics/Vty/Image/Internal.hs+5−4
@@ -38,12 +38,13 @@ clipText txt leftSkip rightClip =
3838 txt' = if padPrefix then TL.cons '…' (TL.drop (toDrop+1) txt) else TL.drop toDrop txt
3939 (toTake,padSuffix) = clipForCharWidth rightClip txt' 0
4040 txt'' = TL.append (TL.take toTake txt') (if padSuffix then TL.singleton '…' else TL.empty)
41− clipForCharWidth 0 _ n = (n, False)
41+ -- Note: some characters and zero-width and combining characters
42+ -- combine to the left, so keep taking characters even if the width
43+ -- is zero.
4244 clipForCharWidth w t n
4345 | TL.null t = (n, False)
44− | w < cw = (n, True)
45− | w == cw = (n+1, False)
46− | w > cw = clipForCharWidth (w - cw) (TL.tail t) (n + 1)
46+ | w < cw = (n, w /= 0)
47+ | otherwise = clipForCharWidth (w - cw) (TL.tail t) (n + 1)
4748 where cw = safeWcwidth (TL.head t)
4849 clipForCharWidth _ _ _ = error "clipForCharWidth applied to undefined"
4950 in txt''
src/Graphics/Vty/Output/Interface.hs+10−3
@@ -166,13 +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
171− NoCursor -> mempty
174+ NoCursor -> mempty
175+ AbsoluteCursor x y ->
176+ writeShowCursor dc `mappend`
177+ writeMoveCursor dc (clampX x) (clampY y)
172178 Cursor x y ->
173179 let m = cursorOutputMap ops $ picCursor pic
174180 (ox, oy) = charToOutputPos m (x,y)
175− in writeShowCursor dc `mappend` writeMoveCursor dc ox oy
181+ in writeShowCursor dc `mappend`
182+ writeMoveCursor dc (clampX ox) (clampY oy)
176183 )
177184 -- ... then serialize
178185 outputByteBuffer (contextDevice dc) (writeToByteString out)
src/Graphics/Vty/Picture.hs+9−6
@@ -69,13 +69,16 @@ picForLayers is = Picture
6969--
7070-- todo: The Cursor can be given a (character,row) offset outside of the visible bounds of the
7171-- output region. In this case the cursor will not be shown.
72−data Cursor =
72+data Cursor =
73+ -- | Hide the cursor
7374 NoCursor
74− | Cursor Int Int
75+ -- | Show the cursor at the given logical column accounting for char width and row
76+ | Cursor !Int !Int
77+ -- | Show the cursor at the given absolute terminal column and row
78+ | AbsoluteCursor !Int !Int
7579
7680instance NFData Cursor where
77− rnf NoCursor = ()
78− rnf (Cursor w h) = w `seq` h `seq` ()
81+ rnf c = c `seq` ()
7982
8083-- | A 'Picture' has a background pattern. The background is either ClearBackground. Which shows the
8184-- layer below or is blank if the bottom layer. Or the background pattern is a character and a
@@ -85,11 +88,11 @@ instance NFData Cursor where
8588-- \todo The current attribute is always set to the default attributes at the start of updating the
8689-- screen to a picture.
8790data Background
88− = Background
91+ = Background
8992 { backgroundChar :: Char
9093 , backgroundAttr :: Attr
9194 }
92− -- | A ClearBackground is:
95+ -- | A ClearBackground is:
9396 --
9497 -- * the space character if there are remaining non-skip ops
9598 --
vty.cabal+1−1
@@ -1,5 +1,5 @@
11name: vty
2−version: 5.9.1
2+version: 5.10
33license: BSD3
44license-file: LICENSE
55author: AUTHORS