vty-5.8.1: A simple terminal UI library

Safe HaskellNone



Vty supports input and output to terminal devices.

See the vty-examples package for a number of examples.

 import Graphics.Vty

 main = do
     cfg <- standardIOConfig
     vty <- mkVty cfg
     let line0 = string (defAttr ` withForeColor ` green) "first line"
         line1 = string (defAttr ` withBackColor ` blue) "second line"
         img = line0 <-> line1
         pic = picForImage img
     update vty pic
     e <- nextEvent vty
     shutdown vty
     print ("Last event was: " ++ show e)

Good sources of documentation for terminal programming are:



data Vty Source #

The main object. At most one should be created.

The use of Vty typically follows this process:

  1. initialize vty
  2. use the update equation of Vty to display a picture
  3. repeat
  4. shutdown vty.

An alternative to tracking the Vty instance is to use withVty in Graphics.Vty.Inline.Unsafe.

This does not assure any thread safety. In theory, as long as an update action is not executed when another update action is already then it's safe to call this on multiple threads.

todo Remove explicit shutdown requirement.




  • update :: Picture -> IO ()

    Outputs the given Picture. Equivalent to outputPicture applied to a display context implicitly managed by Vty. The managed display context is reset on resize.

  • nextEvent :: IO Event

    Get one Event object, blocking if necessary. This will refresh the terminal if the event is a EvResize.

  • inputIface :: Input

    The input interface. See Input

  • outputIface :: Output

    The output interface. See Output

  • refresh :: IO ()

    Refresh the display. nextEvent will refresh the display if a resize occurs. If other programs output to the terminal and mess up the display then the application might want to force a refresh.

  • shutdown :: IO ()

    Clean up after vty. The above methods will throw an exception if executed after this is executed.

mkVty :: Config -> IO Vty Source #

Set up the state object for using vty. At most one state object should be created at a time for a given terminal device.

The specified config is added to the userConfig. With the userConfig taking precedence. See Graphics.Vty.Config

For most applications mkVty def is sufficient.

type DisplayRegion = (Int, Int) Source #

Named alias for a Int pair

data Mode Source #

Modal terminal features that can be enabled and disabled.