vty-5.4.0: A simple terminal UI library

Safe Haskell | None
Language | Haskell2010

Graphics.Vty.Output.Interface

Synopsis

- data Output = Output {
  - terminalID :: String
  - releaseTerminal :: forall m. MonadIO m => m ()
  - reserveDisplay :: forall m. MonadIO m => m ()
  - releaseDisplay :: forall m. MonadIO m => m ()
  - displayBounds :: forall m. MonadIO m => m DisplayRegion
  - outputByteBuffer :: ByteString -> IO ()
  - contextColorCount :: Int
  - supportsCursorVisibility :: Bool
  - assumedStateRef :: IORef AssumedState
  - mkDisplayContext :: forall m. MonadIO m => Output -> DisplayRegion -> m DisplayContext
  }
- displayContext :: MonadIO m => Output -> DisplayRegion -> m DisplayContext
- data AssumedState = AssumedState {
  - prevFattr :: Maybe FixedAttr
  - prevOutputOps :: Maybe DisplayOps
  }
- initialAssumedState :: AssumedState
- data DisplayContext = DisplayContext {
  - contextDevice :: Output
  - contextRegion :: DisplayRegion
  - writeMoveCursor :: Int -> Int -> Write
  - writeShowCursor :: Write
  - writeHideCursor :: Write
  - writeSetAttr :: FixedAttr -> Attr -> DisplayAttrDiff -> Write
  - writeDefaultAttr :: Write
  - writeRowEnd :: Write
  - inlineHack :: IO ()
  }
- writeUtf8Text :: ByteString -> Write
- outputPicture :: MonadIO m => DisplayContext -> Picture -> m ()
- writeOutputOps :: DisplayContext -> FixedAttr -> [Bool] -> DisplayOps -> Write
- writeSpanOps :: DisplayContext -> Int -> FixedAttr -> SpanOps -> Write
- writeSpanOp :: DisplayContext -> SpanOp -> FixedAttr -> (Write, FixedAttr)
- data CursorOutputMap = CursorOutputMap {
  - charToOutputPos :: (Int, Int) -> (Int, Int)
  }
- cursorOutputMap :: DisplayOps -> Cursor -> CursorOutputMap
- cursorColumnOffset :: DisplayOps -> Int -> Int -> Int
- limitAttrForDisplay :: Output -> Attr -> Attr

# Documentation

data Output Source

Constructors

Output |

Fields

terminalID :: String

  Text identifier for the output device. Used for debugging.

releaseTerminal :: forall m. MonadIO m => m ()
reserveDisplay :: forall m. MonadIO m => m ()

  Clear the display and initialize the terminal to some initial display state.

  The expectation of a program is that the display starts in some initial state. The initial state would consist of fixed values:

  - cursor at top left
  - UTF-8 character encoding
  - drawing characteristics are the default

  The abstract operation I think all these behaviors are instances of is reserving exclusive access to a display such that:

  - The previous state cannot be determined
  - When exclusive access to a display is released the display returns to the previous state.
releaseDisplay :: forall m. MonadIO m => m ()

  Return the display to the state before `reserveDisplay` If no previous state then set the display state to the initial state.

displayBounds :: forall m. MonadIO m => m DisplayRegion

  Returns the current display bounds.

outputByteBuffer :: ByteString -> IO ()

  Output the byte string to the terminal device.

contextColorCount :: Int

  Maximum number of colors supported by the context.

supportsCursorVisibility :: Bool

  if the cursor can be shown / hidden

assumedStateRef :: IORef AssumedState
mkDisplayContext :: forall m. MonadIO m => Output -> DisplayRegion -> m DisplayContext

  Acquire display access to the given region of the display. Currently all regions have the upper left corner of (0,0) and the lower right corner at (max displayWidth providedWidth, max displayHeight providedHeight)

displayContext :: MonadIO m => Output -> DisplayRegion -> m DisplayContext Source

data AssumedState Source

Constructors

AssumedState |

Fields

prevFattr :: Maybe FixedAttr
prevOutputOps :: Maybe DisplayOps

initialAssumedState :: AssumedState Source

data DisplayContext Source

Constructors

DisplayContext |

Fields

contextDevice :: Output
contextRegion :: DisplayRegion

  Provide the bounds of the display context.

writeMoveCursor :: Int -> Int -> Write
writeShowCursor :: Write
writeHideCursor :: Write
writeSetAttr :: FixedAttr -> Attr -> DisplayAttrDiff -> Write
writeDefaultAttr :: Write

  Reset the display attributes to the default display attributes

writeRowEnd :: Write
inlineHack :: IO ()

  See `inlineHack`

writeUtf8Text :: ByteString -> Write Source

All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.

outputPicture :: MonadIO m => DisplayContext -> Picture -> m () Source

Displays the given `Picture`.

1. The image is cropped to the display size.
2. Converted into a sequence of attribute changes and text spans.
3. The cursor is hidden.
4. Serialized to the display.
5. The cursor is then shown and positioned or kept hidden.

todo: specify possible IO exceptions. abstract from IO monad to a MonadIO instance.

writeOutputOps :: DisplayContext -> FixedAttr -> [Bool] -> DisplayOps -> Write Source

writeSpanOps :: DisplayContext -> Int -> FixedAttr -> SpanOps -> Write Source

writeSpanOp :: DisplayContext -> SpanOp -> FixedAttr -> (Write, FixedAttr) Source

data CursorOutputMap Source

The cursor position is given in X,Y character offsets. Due to multi-column characters this needs to be translated to column, row positions.

Constructors

CursorOutputMap |

Fields

charToOutputPos :: (Int, Int) -> (Int, Int)

cursorOutputMap :: DisplayOps -> Cursor -> CursorOutputMap Source

cursorColumnOffset :: DisplayOps -> Int -> Int -> Int Source

limitAttrForDisplay :: Output -> Attr -> Attr Source

Not all terminals support all display attributes. This filters a display attribute to what the given terminal can display.