1-- | Vty supports input and output to terminal devices.
3-- - The input is provides as a sequence of 'Event's.
5-- - The output is defined by a 'Picture'. Which is one or more layers of 'Image's.
6-- The constructors in "Graphics.Vty.Image.Internal" should not be used directly. The module
7-- "Graphics.Vty.Image" provides a number of constructor equations that will build correct
8-- 'Image' values. See 'string', '<|>', and '<->' for starters.
10-- - 'Image's can be styled using 'Attr'. See "Graphics.Vty.Attributes".
12-- Good sources of documentation for terminal programming are:
14-- - <https://github.com/b4winckler/vim/blob/master/src/term.c>
16-- - <http://invisible-island.net/xterm/ctlseqs/ctlseqs.html>
18-- - <http://ulisse.elettra.trieste.it/services/doc/serial/config.html>
20-- - <http://www.leonerd.org.uk/hacks/hints/xterm-8bit.html>
22-- - <http://www.unixwiz.net/techtips/termios-vmin-vtime.html>
24-- - <http://vt100.net/docs/vt100-ug/chapter3.html vt100 control sequences>
25module Graphics.Vty ( Vty(..)
27 , module Graphics.Vty.Input
28 , module Graphics.Vty.Output
29 , module Graphics.Vty.Picture
34import Graphics.Vty.Prelude
36import Graphics.Vty.Input
37import Graphics.Vty.Output
38import Graphics.Vty.Picture
40import Control.Concurrent
45import qualified System.Console.Terminfo as Terminfo
47-- | The main object. At most one should be created.
49-- The use of Vty typically follows this process:
53-- 1. use the update equation of Vty to display a picture
59-- An alternative to tracking the Vty instance is to use 'withVty' in "Graphics.Vty.Inline.Unsafe".
61-- This does not assure any thread safety. In theory, as long as an update action is not executed
62-- when another update action is already then it's safe to call this on multiple threads.
64-- \todo Remove explicit `shutdown` requirement.
66 { -- | Outputs the given Picture. Equivalent to 'output_picture' applied to a display context
67 -- implicitly managed by Vty. The managed display context is reset on resize.
68 update :: Picture -> IO ()
69 -- | Get one Event object, blocking if necessary. This will refresh the terminal if the event
71 , next_event :: IO Event
72 -- | The input interface. See 'Input'
73 , input_iface :: Input
74 -- | The output interface. See 'Output'
75 , output_iface :: Output
76 -- | Refresh the display. Normally the library takes care of refreshing. Nonetheless, some
77 -- other program might output to the terminal and mess up the display. In that case the
78 -- application might want to force a refresh.
80 -- | Clean up after vty.
81 -- The above methods will throw an exception if executed after this is executed.
85-- | Set up the state object for using vty. At most one state object should be
87mkVty :: Config -> IO Vty
89 input <- input_for_current_terminal config
90 out <- output_for_current_terminal
93intMkVty :: Input -> Output -> IO Vty
94intMkVty input out = do
100 last_pic_ref <- newIORef Nothing
101 last_update_ref <- newIORef Nothing
103 let inner_update in_pic = do
104 b@(w,h) <- display_bounds out
105 let cursor = pic_cursor in_pic
106 in_pic' = case cursor of
117 in in_pic { pic_cursor = Cursor x' y' }
119 mlast_update <- readIORef last_update_ref
120 update_data <- case mlast_update of
122 dc <- display_context out b
123 output_picture dc in_pic'
125 Just (last_bounds, last_context) -> do
128 dc <- display_context out b
129 output_picture dc in_pic'
132 output_picture last_context in_pic'
133 return (b, last_context)
134 writeIORef last_update_ref $ Just update_data
135 writeIORef last_pic_ref $ Just in_pic'
138 = writeIORef last_update_ref Nothing
139 >> readIORef last_pic_ref
140 >>= maybe ( return () ) ( \pic -> inner_update pic )
142 let gkey = do k <- readChan $ _event_channel input
144 (EvResize _ _) -> inner_refresh
145 >> display_bounds out
146 >>= return . (\(w,h)-> EvResize w h)
149 return $ Vty { update = inner_update
151 , input_iface = input
153 , refresh = inner_refresh
154 , shutdown = shutdown_io
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list