Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- main :: IO a -> IO a
- data InitError
- data Cell = Cell !Char !Attr !Attr
- set :: (col ~ Int, row ~ Int) => col -> row -> Cell -> IO ()
- buffer :: (row ~ Int, col ~ Int) => IO (StorableArray (row, col) Cell)
- clear :: (fg ~ Attr, bg ~ Attr) => fg -> bg -> IO ()
- flush :: IO ()
- size :: (width ~ Int, height ~ Int) => IO (width, height)
- setCursor :: (col ~ Int, row ~ Int) => col -> row -> IO ()
- hideCursor :: IO ()
- data Event
- = EventKey !Key !Bool
- | EventResize !Int !Int
- | EventMouse !Mouse !Int !Int
- data Key
- = KeyChar Char
- | KeyArrowDown
- | KeyArrowLeft
- | KeyArrowRight
- | KeyArrowUp
- | KeyBackspace
- | KeyBackspace2
- | KeyCtrl2
- | KeyCtrl3
- | KeyCtrl4
- | KeyCtrl5
- | KeyCtrl6
- | KeyCtrl7
- | KeyCtrl8
- | KeyCtrlA
- | KeyCtrlB
- | KeyCtrlBackslash
- | KeyCtrlC
- | KeyCtrlD
- | KeyCtrlE
- | KeyCtrlF
- | KeyCtrlG
- | KeyCtrlH
- | KeyCtrlI
- | KeyCtrlJ
- | KeyCtrlK
- | KeyCtrlL
- | KeyCtrlLsqBracket
- | KeyCtrlM
- | KeyCtrlN
- | KeyCtrlO
- | KeyCtrlP
- | KeyCtrlQ
- | KeyCtrlR
- | KeyCtrlRsqBracket
- | KeyCtrlS
- | KeyCtrlSlash
- | KeyCtrlT
- | KeyCtrlTilde
- | KeyCtrlU
- | KeyCtrlUnderscore
- | KeyCtrlV
- | KeyCtrlW
- | KeyCtrlX
- | KeyCtrlY
- | KeyCtrlZ
- | KeyDelete
- | KeyEnd
- | KeyEnter
- | KeyEsc
- | KeyF1
- | KeyF10
- | KeyF11
- | KeyF12
- | KeyF2
- | KeyF3
- | KeyF4
- | KeyF5
- | KeyF6
- | KeyF7
- | KeyF8
- | KeyF9
- | KeyHome
- | KeyInsert
- | KeyPageDn
- | KeyPageUp
- | KeySpace
- | KeyTab
- data Mouse
- poll :: IO Event
- data PollError = PollError
- data Attr
- black :: Attr
- red :: Attr
- green :: Attr
- yellow :: Attr
- blue :: Attr
- magenta :: Attr
- cyan :: Attr
- white :: Attr
- bold :: Attr
- underline :: Attr
- reverse :: Attr
- data InputMode
- data MouseMode
- getInputMode :: IO InputMode
- setInputMode :: InputMode -> IO ()
- data OutputMode
- getOutputMode :: IO OutputMode
- setOutputMode :: OutputMode -> IO ()
Documentation
This module is intended to be imported qualified.
import qualified Termbox
Initialization
Run a termbox
program and restore the terminal state afterwards. May
throw an InitError
exception.
Initialization errors that can be thrown by main
.
Instances
Show InitError Source # | |
Exception InitError Source # | |
Defined in Termbox toException :: InitError -> SomeException # fromException :: SomeException -> Maybe InitError # displayException :: InitError -> String # |
Terminal contents
A Cell
contains a character, foreground attribute, and background
attribute.
set :: (col ~ Int, row ~ Int) => col -> row -> Cell -> IO () Source #
Set the Cell
at the given coordinates.
clear :: (fg ~ Attr, bg ~ Attr) => fg -> bg -> IO () Source #
Clear the back buffer with the given foreground and background attributes.
Terminal size
size :: (width ~ Int, height ~ Int) => IO (width, height) Source #
Get the terminal width and height.
Cursor manipulation
hideCursor :: IO () Source #
Hide the cursor.
Event handling
A input event.
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) |
A key event.
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.
An error occurred when poll
ing.
Instances
Show PollError Source # | |
Exception PollError Source # | |
Defined in Termbox toException :: PollError -> SomeException # fromException :: SomeException -> Maybe PollError # displayException :: PollError -> String # |
Attributes
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 Attr
s 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.
Terminal modes
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.
The mouse mode.
- No. Don't handle mouse events.
- Yes. Handle mouse events.
MouseModeNo | Default. |
MouseModeYes |
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.
Instances
Eq OutputMode Source # | |
Defined in Termbox (==) :: OutputMode -> OutputMode -> Bool # (/=) :: OutputMode -> OutputMode -> Bool # | |
Ord OutputMode Source # | |
Defined in Termbox compare :: OutputMode -> OutputMode -> Ordering # (<) :: OutputMode -> OutputMode -> Bool # (<=) :: OutputMode -> OutputMode -> Bool # (>) :: OutputMode -> OutputMode -> Bool # (>=) :: OutputMode -> OutputMode -> Bool # max :: OutputMode -> OutputMode -> OutputMode # min :: OutputMode -> OutputMode -> OutputMode # | |
Show OutputMode Source # | |
Defined in Termbox showsPrec :: Int -> OutputMode -> ShowS # show :: OutputMode -> String # showList :: [OutputMode] -> ShowS # |
getOutputMode :: IO OutputMode Source #
Get the current output mode.
setOutputMode :: OutputMode -> IO () Source #
Set the output mode.