on master help sign in
Add support for absolute cursor positioning
818eed2Eric Mertens
CHANGELOG+3
@@ -1,3 +1,6 @@
1+5.10
2+ - Add aboslute cursor positioning mode AbsoluteCursor to Cursor
3+
15.9.1
45.9.1
2 - Vty now only emits UTF8 charset sequences in terminals without a
5 - Vty now only emits UTF8 charset sequences in terminals without a
3 preexisting UTF8 declaration to avoid emitting garbage sequences
6 preexisting UTF8 declaration to avoid emitting garbage sequences
src/Graphics/Vty.hs+5
@@ -132,6 +132,11 @@ intMkVty input out = do
132 b@(w,h) <- displayBounds out
132 b@(w,h) <- displayBounds out
133 let cursor = picCursor inPic
133 let cursor = picCursor inPic
134 inPic' = case cursor of
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
135 Cursor x y ->
140 Cursor x y ->
136 let
141 let
137 x' = case x of
142 x' = case x of
src/Graphics/Vty/Output/Interface.hs+3−1
@@ -168,7 +168,9 @@ outputPicture dc pic = liftIO $ do
168 `mappend`
168 `mappend`
169 (case picCursor pic of
169 (case picCursor pic of
170 _ | not manipCursor -> mempty
170 _ | not manipCursor -> mempty
171− NoCursor -> mempty
171+ NoCursor -> mempty
172+ AbsoluteCursor x y ->
173+ writeShowCursor dc `mappend` writeMoveCursor dc x y
172 Cursor x y ->
174 Cursor x y ->
173 let m = cursorOutputMap ops $ picCursor pic
175 let m = cursorOutputMap ops $ picCursor pic
174 (ox, oy) = charToOutputPos m (x,y)
176 (ox, oy) = charToOutputPos m (x,y)
src/Graphics/Vty/Picture.hs+9−6
@@ -69,13 +69,16 @@ picForLayers is = Picture
69--
69--
70-- todo: The Cursor can be given a (character,row) offset outside of the visible bounds of the
70-- todo: The Cursor can be given a (character,row) offset outside of the visible bounds of the
71-- output region. In this case the cursor will not be shown.
71-- output region. In this case the cursor will not be shown.
72−data Cursor =
72+data Cursor =
73+ -- | Hide the cursor
73 NoCursor
74 NoCursor
75+ -- | Show the cursor at the given logical column accounting for char width and row
74− | Cursor Int Int
76+ | Cursor !Int !Int
77+ -- | Show the cursor at the given absolute terminal column and row
78+ | AbsoluteCursor !Int !Int
75
79
76instance NFData Cursor where
80instance NFData Cursor where
77− rnf NoCursor = ()
81+ rnf c = c `seq` ()
78− rnf (Cursor w h) = w `seq` h `seq` ()
79
82
80-- | A 'Picture' has a background pattern. The background is either ClearBackground. Which shows the
83-- | A 'Picture' has a background pattern. The background is either ClearBackground. Which shows the
81-- layer below or is blank if the bottom layer. Or the background pattern is a character and a
84-- 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
85-- \todo The current attribute is always set to the default attributes at the start of updating the
88-- \todo The current attribute is always set to the default attributes at the start of updating the
86-- screen to a picture.
89-- screen to a picture.
87data Background
90data Background
88− = Background
91+ = Background
89 { backgroundChar :: Char
92 { backgroundChar :: Char
90 , backgroundAttr :: Attr
93 , backgroundAttr :: Attr
91 }
94 }
92− -- | A ClearBackground is:
95+ -- | A ClearBackground is:
93 --
96 --
94 -- * the space character if there are remaining non-skip ops
97 -- * the space character if there are remaining non-skip ops
95 --
98 --
vty.cabal+1−1
@@ -1,5 +1,5 @@
1name: vty
1name: vty
2−version: 5.9.1
2+version: 5.10
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: AUTHORS
5author: AUTHORS