@@ -21,7 +21,7 @@
2121--
2222-- - <http://www.unixwiz.net/techtips/termios-vmin-vtime.html>
2323--
24−-- - <<http://vt100.net/docs/vt100-ug/chapter3.html vt100 control sequences>
24+-- - <http://vt100.net/docs/vt100-ug/chapter3.html vt100 control sequences>
2525module Graphics.Vty ( Vty(..)
2626 , mkVty
2727 , mkVtyEscDelay
@@ -46,34 +46,31 @@ import Data.IORef
4646import qualified System.Console.Terminfo as Terminfo
4747
4848-- | The main object. At most one should be created.
49−-- An alternative is to use unsafePerformIO to automatically create a singleton Vty instance when
50−-- required.
49+--
50+-- The use of Vty typically follows this process:
51+--
52+-- 0. initialize vty
53+--
54+-- 1. use the update equation of Vty to display a picture
55+--
56+-- 2. repeat
57+--
58+-- 3. shutdown vty.
59+--
60+-- An alternative to tracking the Vty instance is to use 'withVty' in "Graphics.Vty.Inline.Unsafe".
5161--
5262-- This does not assure any thread safety. In theory, as long as an update action is not executed
5363-- when another update action is already then it's safe to call this on multiple threads.
64+--
65+-- \todo Remove explicit `shutdown` requirement.
5466data Vty = Vty
5567 { -- | Outputs the given Picture. Equivalent to output_picture applied to a display context
5668 -- implicitly managed by Vty.
5769 update :: Picture -> IO ()
5870 -- | Get one Event object, blocking if necessary.
5971 , next_event :: IO Event
60− -- | The terminal device interface. See `Interface`
61− --
62− -- The use of Vty typically follows this process:
63− --
64− -- 0. initialize vty
65− --
66− -- 1. use the update equation of Vty to display a picture
67− --
68− -- 2. repeat
69− --
70− -- 3. shutdown vty.
71− --
72− -- todo: provide a similar abstraction to Graphics.Vty.Output for input. Use haskeline's
73− -- input backend for implementation.
74− --
75− -- todo: remove explicit `shutdown` requirement.
76− , terminal :: Output
72+ -- | The output interface. See `Output`
73+ , output_iface :: Output
7774 -- | Refresh the display. Normally the library takes care of refreshing. Nonetheless, some
7875 -- other program might output to the terminal and mess the display. In that case the user
7976 -- might want to force a refresh.
@@ -95,42 +92,42 @@ mkVty = mkVtyEscDelay defaultEscDelay
9592mkVtyEscDelay :: Int -> IO Vty
9693mkVtyEscDelay escDelay = do
9794 term_info <- Terminfo.setupTermFromEnv
98− t <- current_terminal
95+ t <- output_for_current_terminal
9996 reserve_display t
10097 (kvar, endi) <- initTermInput escDelay term_info
10198 intMkVty kvar ( endi >> release_display t >> release_terminal t ) t
10299
103100intMkVty :: IO Event -> IO () -> Output -> IO Vty
104−intMkVty kvar fend t = do
101+intMkVty kvar fend out = do
105102 last_pic_ref <- newIORef Nothing
106103 last_update_ref <- newIORef Nothing
107104
108105 let inner_update in_pic = do
109− b@(w,h) <- display_bounds t
106+ b@(w,h) <- display_bounds out
110107 let cursor = pic_cursor in_pic
111108 in_pic' = case cursor of
112109 Cursor x y ->
113110 let
114111 x' = case x of
115− _ | x >= 0x80000000 -> 0
116− | x >= w -> w - 1
117− | otherwise -> x
112+ _ | x < 0 -> 0
113+ | x >= w -> w - 1
114+ | otherwise -> x
118115 y' = case y of
119− _ | y >= 0x80000000 -> 0
120− | y >= h -> h - 1
121− | otherwise -> y
116+ _ | y < 0 -> 0
117+ | y >= h -> h - 1
118+ | otherwise -> y
122119 in in_pic { pic_cursor = Cursor x' y' }
123120 _ -> in_pic
124121 mlast_update <- readIORef last_update_ref
125122 update_data <- case mlast_update of
126123 Nothing -> do
127− dc <- display_context t b
124+ dc <- display_context out b
128125 output_picture dc in_pic'
129126 return (b, dc)
130127 Just (last_bounds, last_context) -> do
131128 if b /= last_bounds
132129 then do
133− dc <- display_context t b
130+ dc <- display_context out b
134131 output_picture dc in_pic'
135132 return (b, dc)
136133 else do
@@ -146,14 +143,14 @@ intMkVty kvar fend t = do
146143
147144 let gkey = do k <- kvar
148145 case k of
149− (EvResize _ _) -> inner_refresh
150− >> display_bounds t
146+ (EvResize _ _) -> inner_refresh
147+ >> display_bounds out
151148 >>= return . (\(w,h)-> EvResize w h)
152149 _ -> return k
153150
154151 return $ Vty { update = inner_update
155152 , next_event = gkey
156− , terminal = t
153+ , output_iface = out
157154 , refresh = inner_refresh
158155 , shutdown = fend
159156 }