Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type TermboxEvent = Event
- run :: (Event TermboxEvent -> Behavior (Int, Int) -> MomentIO (Behavior (Cells, Cursor), Event a)) -> IO a
- black :: Attr
- blue :: Attr
- bold :: Attr
- cyan :: Attr
- green :: Attr
- magenta :: Attr
- red :: Attr
- reverse :: Attr
- underline :: Attr
- white :: Attr
- yellow :: Attr
- set :: Int -> Int -> Cell -> Cells
- data Attr
- data Cell = Cell !Char !Attr !Attr
- data Cells
- data Cursor
- data Event
- = EventKey !Key
- | EventResize !Int !Int
- | EventMouse !Mouse !Int !Int
- data InitError
- data Key
- = KeyChar Char
- | KeyArrowDown
- | KeyArrowLeft
- | KeyArrowRight
- | KeyArrowUp
- | KeyBackspace
- | KeyCtrlBackspace
- | KeyCtrl6
- | KeyCtrl8
- | KeyCtrlA
- | KeyCtrlB
- | KeyCtrlBackslash
- | KeyCtrlC
- | KeyCtrlD
- | KeyCtrlE
- | KeyCtrlF
- | KeyCtrlG
- | KeyCtrlJ
- | KeyCtrlK
- | KeyCtrlL
- | KeyCtrlN
- | KeyCtrlO
- | KeyCtrlP
- | KeyCtrlQ
- | KeyCtrlR
- | KeyCtrlRsqBracket
- | KeyCtrlS
- | KeyCtrlSlash
- | KeyCtrlTilde
- | KeyCtrlT
- | KeyCtrlU
- | 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
- pattern KeyCtrl2 :: Key
- pattern KeyCtrl3 :: Key
- pattern KeyCtrl4 :: Key
- pattern KeyCtrl5 :: Key
- pattern KeyCtrl7 :: Key
- pattern KeyCtrlH :: Key
- pattern KeyCtrlI :: Key
- pattern KeyCtrlLsqBracket :: Key
- pattern KeyCtrlM :: Key
- pattern KeyCtrlUnderscore :: Key
- data Mouse
- data PollError = PollError
Introduction
This module is intended to be imported qualified:
import qualified Termbox.Banana as Termbox
👉 Quick start example
This is a program that displays the last key pressed, and quits on Esc
:
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} module Main where import Reactive.Banana import Reactive.Banana.Frameworks import qualified Termbox.Banana as Termbox main :: IO () main = Termbox.run
moment moment :: Event Termbox.Event
-> Behavior (Int, Int) -> MomentIO (Behavior (Termbox.Cells
, Termbox.Cursor
), Event ()) moment eEvent _bSize = do let eQuit :: Event () eQuit = () <$ filterE isKeyEsc eEvent bLatestEvent :: Behavior (Maybe Termbox.Event
) <- stepper Nothing (Just <$> eEvent) let bCells :: Behavior Termbox.Cells
bCells = maybe mempty renderEvent <$> bLatestEvent let bScene :: Behavior (Termbox.Cells
, Termbox.Cursor
) bScene = (,) <$> bCells <*> pure Termbox.NoCursor
pure (bScene, eQuit) renderEvent :: Termbox.Event
-> Termbox.Cells
renderEvent = foldMap (\(i, c) -> Termbox.set i 0 (Termbox.Cell
c mempty mempty)) . zip [0..] . show isKeyEsc :: Termbox.Event
-> Bool isKeyEsc = \case Termbox.EventKey
Termbox.KeyEsc
-> True _ -> False
Core API
type TermboxEvent = Event Source #
A termbox
event. This type alias exists only for Haddock readability;
in code, you are encouraged to use
Event
forreactive-banana
eventsTermbox.Event
fortermbox
events
run :: (Event TermboxEvent -> Behavior (Int, Int) -> MomentIO (Behavior (Cells, Cursor), Event a)) -> IO a Source #
Run a termbox
program with the specified input and output modes.
Given
- the terminal event stream
- the time-varying terminal size (width, then height)
return
- a time-varying scene to render
- an event stream of arbitrary values, only the first of which is relevant,
which ends the
termbox
program and returns from themain
action.
Re-exports from termbox
EventKey !Key | |
EventResize !Int !Int | |
EventMouse !Mouse !Int !Int |
Instances
Exception InitError | |
Defined in Termbox toException :: InitError -> SomeException # fromException :: SomeException -> Maybe InitError # displayException :: InitError -> String # | |
Show InitError | |
pattern KeyCtrlLsqBracket :: Key #
pattern KeyCtrlUnderscore :: Key #
Instances
Exception PollError | |
Defined in Termbox.Event toException :: PollError -> SomeException # fromException :: SomeException -> Maybe PollError # displayException :: PollError -> String # | |
Show PollError | |