module Termbox.Modes where
import Data.Bits
data InputMode = InputMode
{ isEsc :: Bool
, isAlt :: Bool
, isMouse :: Bool
} deriving (Show, Eq)
toInputMode :: Int -> InputMode
toInputMode bits = InputMode
{ isEsc = 0 /= bits .&. 1
, isAlt = 0 /= bits .&. 2
, isMouse = 0 /= bits .&. 4
}
fromInputMode :: InputMode -> Int
fromInputMode mode =
let e = if isEsc mode then 1 else 0
a = if isAlt mode then 2 else 0
m = if isMouse mode then 4 else 0
in e .|. a .|. m
inputMode :: InputMode
inputMode = InputMode False False False
data OutputMode = OutputMode
{ isNormal :: Bool
, is256 :: Bool
, is216 :: Bool
, isGrayscale :: Bool
} deriving (Show, Eq)
toOutputMode :: Int -> OutputMode
toOutputMode bits = OutputMode
{ isNormal = 0 /= bits .&. 1
, is256 = 0 /= bits .&. 2
, is216 = 0 /= bits .&. 3
, isGrayscale = 0 /= bits .&. 4
}
fromOutputMode :: OutputMode -> Int
fromOutputMode mode =
let n = if isNormal mode then 1 else 0
h = if is256 mode then 2 else 0
l = if is216 mode then 3 else 0
g = if isGrayscale mode then 4 else 0
in n .|. h .|. l .|. g
outputMode :: OutputMode
outputMode = OutputMode False False False False