1-- | Vty provides interfaces for both terminal input and terminal
4-- - Input to the terminal is provided to the Vty application as a
5-- sequence of 'Event's.
7-- - Output is provided to Vty by the application in the form of a
8-- 'Picture'. A 'Picture' is one or more layers of 'Image's.
9-- 'Image' values can be built by the various constructors in
10-- "Graphics.Vty.Image". Output can be syled using 'Attr' (attribute)
11-- values in the "Graphics.Vty.Attributes" module.
14-- import "Graphics.Vty"
17-- cfg <- 'standardIOConfig'
19-- let line0 = 'string' ('defAttr' ` 'withForeColor' ` 'green') \"first line\"
20-- line1 = 'string' ('defAttr' ` 'withBackColor' ` 'blue') \"second line\"
21-- img = line0 '<->' line1
22-- pic = 'picForImage' img
24-- e <- 'nextEvent' vty
26-- 'print' (\"Last event was: \" '++' 'show' e)
32 , module Graphics.Vty.Config
33 , module Graphics.Vty.Input
34 , module Graphics.Vty.Output
35 , module Graphics.Vty.Output.Interface
36 , module Graphics.Vty.Picture
37 , module Graphics.Vty.Image
38 , module Graphics.Vty.Attributes
42import Graphics.Vty.Config
43import Graphics.Vty.Input
44import Graphics.Vty.Output
45import Graphics.Vty.Output.Interface
46import Graphics.Vty.Picture
47import Graphics.Vty.Image
48import Graphics.Vty.Attributes
50import Control.Concurrent.STM
55-- | A Vty value represents a handle to the Vty library that the
56-- application must create in order to use Vty.
58-- The use of Vty typically follows this process:
62-- 2. Use 'update' to display a picture.
64-- 3. Use 'nextEvent' to get the next input event.
66-- 4. Depending on the event, go to 2 or 5.
70-- Operations on Vty handles are not thread-safe.
72 { -- | Outputs the given 'Picture'.
73 update :: Picture -> IO ()
74 -- | Get one 'Event' object, blocking if none are available. This
75 -- will refresh the terminal if the event is a 'EvResize'.
76 , nextEvent :: IO Event
77 -- | The input interface. See 'Input'.
79 -- | The output interface. See 'Output'.
80 , outputIface :: Output
81 -- | Refresh the display. 'nextEvent' will refresh the display if
82 -- a resize occurs, but this can be used to refresh the display
83 -- explicitly. If other programs output to the terminal and mess
84 -- up the display then the application might want to force a
85 -- refresh using this function.
87 -- | Clean up after vty. A call to this function is necessary to
88 -- cleanly restore the terminal state before application exit. The
89 -- above methods will throw an exception if executed after this is
94-- | Create a Vty handle. At most one handle should be created at a time
95-- for a given terminal device.
97-- The specified configuration is added to the 'userConfig' with the
98-- 'userConfig' taking precedence. See "Graphics.Vty.Config".
100-- For most applications @mkVty defaultConfig@ is sufficient.
101mkVty :: Config -> IO Vty
103 config <- (<> appConfig) <$> userConfig
104 input <- inputForConfig config
105 out <- outputForConfig config
108intMkVty :: Input -> Output -> IO Vty
109intMkVty input out = do
115 lastPicRef <- newIORef Nothing
116 lastUpdateRef <- newIORef Nothing
118 let innerUpdate inPic = do
119 b <- displayBounds out
120 mlastUpdate <- readIORef lastUpdateRef
121 updateData <- case mlastUpdate of
123 dc <- displayContext out b
124 outputPicture dc inPic
126 Just (lastBounds, lastContext) -> do
129 dc <- displayContext out b
130 outputPicture dc inPic
133 outputPicture lastContext inPic
134 return (b, lastContext)
135 writeIORef lastUpdateRef $ Just updateData
136 writeIORef lastPicRef $ Just inPic
138 let innerRefresh = do
139 writeIORef lastUpdateRef Nothing
140 bounds <- displayBounds out
141 dc <- displayContext out bounds
142 writeIORef (assumedStateRef $ contextDevice dc) initialAssumedState
143 mPic <- readIORef lastPicRef
144 maybe (return ()) innerUpdate mPic
146 let gkey = do k <- atomically $ readTChan $ _eventChannel input
148 (EvResize _ _) -> displayBounds out
149 >>= return . (\(w,h)-> EvResize w h)
152 return $ Vty { update = innerUpdate
156 , refresh = innerRefresh
157 , shutdown = shutdownIo
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