on master help sign in
Add support for absolute cursor positioning

This allows advanced applications to compute their own direct cursor placement by absolute column without having to invert the logical cursor computation. Fixes #94

commit818eed24b3456a6aba1fec1589eff6ce5543d499 authorEric Mertens <emertens@gmail.com> dateThu 1 Sep 2016, 09:05 (10 years ago) parentc264df9
5 files changed+21−8
CHANGELOG+3 src/Graphics/Vty.hs+5 src/Graphics/Vty/Output/Interface.hs+3−1 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
@@ -132,6 +132,11 @@ intMkVty input out = do
132132 b@(w,h) <- displayBounds out
133133 let cursor = picCursor inPic
134134 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
135140 Cursor x y ->
136141 let
137142 x' = case x of
src/Graphics/Vty/Output/Interface.hs+3−1
@@ -168,7 +168,9 @@ outputPicture dc pic = liftIO $ do
168168 `mappend`
169169 (case picCursor pic of
170170 _ | not manipCursor -> mempty
171− NoCursor -> mempty
171+ NoCursor -> mempty
172+ AbsoluteCursor x y ->
173+ writeShowCursor dc `mappend` writeMoveCursor dc x y
172174 Cursor x y ->
173175 let m = cursorOutputMap ops $ picCursor pic
174176 (ox, oy) = charToOutputPos m (x,y)
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