termbox-0.1.0: termbox bindings

Safe HaskellNone
LanguageHaskell2010

Termbox

Contents

Synopsis

Documentation

This module is intended to be imported qualified.

import qualified Termbox

Initialization

main :: IO a -> IO a Source #

Run a termbox program and restore the terminal state afterwards. May throw an InitError exception.

data InitError Source #

Initialization errors that can be thrown by main.

Terminal contents

data Cell Source #

A Cell contains a character, foreground attribute, and background attribute.

Constructors

Cell !Char !Attr !Attr 
Instances
Eq Cell Source # 
Instance details

Defined in Termbox

Methods

(==) :: Cell -> Cell -> Bool #

(/=) :: Cell -> Cell -> Bool #

Show Cell Source # 
Instance details

Defined in Termbox

Methods

showsPrec :: Int -> Cell -> ShowS #

show :: Cell -> String #

showList :: [Cell] -> ShowS #

Storable Cell Source # 
Instance details

Defined in Termbox

Methods

sizeOf :: Cell -> Int #

alignment :: Cell -> Int #

peekElemOff :: Ptr Cell -> Int -> IO Cell #

pokeElemOff :: Ptr Cell -> Int -> Cell -> IO () #

peekByteOff :: Ptr b -> Int -> IO Cell #

pokeByteOff :: Ptr b -> Int -> Cell -> IO () #

peek :: Ptr Cell -> IO Cell #

poke :: Ptr Cell -> Cell -> IO () #

set :: (col ~ Int, row ~ Int) => col -> row -> Cell -> IO () Source #

Set the Cell at the given coordinates.

buffer :: (row ~ Int, col ~ Int) => IO (StorableArray (row, col) Cell) Source #

Get the terminal's internal back buffer as a two-dimensional array of Cells indexed by their coordinates.

Warning: the data is only valid until the next call to clear or flush.

clear :: (fg ~ Attr, bg ~ Attr) => fg -> bg -> IO () Source #

Clear the back buffer with the given foreground and background attributes.

flush :: IO () Source #

Synchronize the internal back buffer with the terminal.

Terminal size

size :: (width ~ Int, height ~ Int) => IO (width, height) Source #

Get the terminal width and height.

Cursor manipulation

setCursor :: (col ~ Int, row ~ Int) => col -> row -> IO () Source #

Set the cursor coordinates.

hideCursor :: IO () Source #

Hide the cursor.

Event handling

data Event Source #

A input event.

Constructors

EventKey !Key !Bool

Key event. The bool indicates the alt modifier.

EventResize !Int !Int

Resize event (width, then height)

EventMouse !Mouse !Int !Int

Mouse event (column, then row)

Instances
Eq Event Source # 
Instance details

Defined in Termbox

Methods

(==) :: Event -> Event -> Bool #

(/=) :: Event -> Event -> Bool #

Show Event Source # 
Instance details

Defined in Termbox

Methods

showsPrec :: Int -> Event -> ShowS #

show :: Event -> String #

showList :: [Event] -> ShowS #

data Mouse Source #

A mouse event.

Instances
Eq Mouse Source # 
Instance details

Defined in Termbox

Methods

(==) :: Mouse -> Mouse -> Bool #

(/=) :: Mouse -> Mouse -> Bool #

Ord Mouse Source # 
Instance details

Defined in Termbox

Methods

compare :: Mouse -> Mouse -> Ordering #

(<) :: Mouse -> Mouse -> Bool #

(<=) :: Mouse -> Mouse -> Bool #

(>) :: Mouse -> Mouse -> Bool #

(>=) :: Mouse -> Mouse -> Bool #

max :: Mouse -> Mouse -> Mouse #

min :: Mouse -> Mouse -> Mouse #

Show Mouse Source # 
Instance details

Defined in Termbox

Methods

showsPrec :: Int -> Mouse -> ShowS #

show :: Mouse -> String #

showList :: [Mouse] -> ShowS #

poll :: IO Event Source #

Block until an Event arrives.

Note: termbox v1.1.2 does not properly handle OS signals that interrupt the underlying select system call, so unfortunately the familiar Ctrl-C will not be able to stop a program stuck in pollEvent.

You can work around this issue by polling in a background thread using the threaded runtime, or simply writing event-handling code that is responsive to intuitive "quit" keys like q and Esc.

This function may throw a PollError exception under mysterious circumstances that are not well-documented in the original C codebase.

data PollError Source #

An error occurred when polling.

Constructors

PollError 

Attributes

data Attr Source #

A cell attribute, which includes its color, and whether or not it is bold, underlined, and/or reversed.

A cell can only have one color, but may be (for example) bold and underlined. The Monoid instance combines Attrs this way, with a left bias. That is,

red <> bold <> black <> underline = red <> bold <> underline

Warning: the Num instance is very partial! It only includes an implementation of fromInteger, for numeric literals.

Instances
Eq Attr Source # 
Instance details

Defined in Termbox

Methods

(==) :: Attr -> Attr -> Bool #

(/=) :: Attr -> Attr -> Bool #

Num Attr Source #

Only fromInteger is defined.

Instance details

Defined in Termbox

Methods

(+) :: Attr -> Attr -> Attr #

(-) :: Attr -> Attr -> Attr #

(*) :: Attr -> Attr -> Attr #

negate :: Attr -> Attr #

abs :: Attr -> Attr #

signum :: Attr -> Attr #

fromInteger :: Integer -> Attr #

Semigroup Attr Source #

Left-biased color; attributes are merged.

Instance details

Defined in Termbox

Methods

(<>) :: Attr -> Attr -> Attr #

sconcat :: NonEmpty Attr -> Attr #

stimes :: Integral b => b -> Attr -> Attr #

Monoid Attr Source # 
Instance details

Defined in Termbox

Methods

mempty :: Attr #

mappend :: Attr -> Attr -> Attr #

mconcat :: [Attr] -> Attr #

black :: Attr Source #

black = 1.

red :: Attr Source #

red = 2.

green :: Attr Source #

green = 3.

yellow :: Attr Source #

yellow = 4.

blue :: Attr Source #

blue = 5.

magenta :: Attr Source #

magenta = 6.

cyan :: Attr Source #

cyan = 7.

white :: Attr Source #

white = 8.

bold :: Attr Source #

Bold modifier attribute.

underline :: Attr Source #

Underline modifier attribute.

reverse :: Attr Source #

Reverse modifier attribute.

Terminal modes

data InputMode Source #

The input modes.

  • Esc. When ESC sequence is in the buffer and it doesn't match any known sequence, ESC means KeyEsc.
  • Alt. When ESC sequence is in the buffer and it doesn't match any known sequence, ESC enables the alt modifier for the next keyboard event.
Instances
Eq InputMode Source # 
Instance details

Defined in Termbox

Ord InputMode Source # 
Instance details

Defined in Termbox

Show InputMode Source # 
Instance details

Defined in Termbox

data MouseMode Source #

The mouse mode.

  • No. Don't handle mouse events.
  • Yes. Handle mouse events.

Constructors

MouseModeNo

Default.

MouseModeYes 
Instances
Eq MouseMode Source # 
Instance details

Defined in Termbox

Ord MouseMode Source # 
Instance details

Defined in Termbox

Show MouseMode Source # 
Instance details

Defined in Termbox

getInputMode :: IO InputMode Source #

Get the current input mode.

setInputMode :: InputMode -> IO () Source #

Set the input mode.

data OutputMode Source #

The output modes.

  • Normal. Supports colors 0..8, which includes all named color attributes exported by this library, e.g. red.
  • Grayscale. Supports colors 0..23.
  • 216. Supports colors 0..216.
  • 256. Supports colors 0..255.

getOutputMode :: IO OutputMode Source #

Get the current output mode.

setOutputMode :: OutputMode -> IO () Source #

Set the output mode.