{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 703
{-# LANGUAGE Safe #-}
#endif
-- |
-- Maintainer  : judah.jacobson@gmail.com
-- Stability   : experimental
-- Portability : portable (FFI)
--
-- The string capabilities in this module are the character sequences
-- corresponding to user input such as arrow keys and function keys.
module System.Console.Terminfo.Keys(
                    -- * The keypad
                    -- | The following commands
                    -- turn the keypad on\/off (@smkx@ and @rmkx@).  
                    -- They have no effect if those capabilities are not defined.  
                    -- For portability between terminals, the keypad should be
                    -- explicitly turned on before accepting user key input.
                    keypadOn,
                    keypadOff,
                    -- * Arrow keys
                    keyUp,
                    keyDown,
                    keyLeft,
                    keyRight,
                    -- * Miscellaneous
                    functionKey,
                    keyBackspace,
                    keyDeleteChar,
                    keyHome,
                    keyEnd,
                    keyPageUp,
                    keyPageDown,
                    keyEnter,
                    ) where

import System.Console.Terminfo.Base

keypadOn :: TermStr s => Capability s
keypadOn :: forall s. TermStr s => Capability s
keypadOn = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"smkx"

keypadOff :: TermStr s => Capability s
keypadOff :: forall s. TermStr s => Capability s
keypadOff = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"rmkx"

keyUp :: Capability String
keyUp :: Capability String
keyUp = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kcuu1"

keyDown :: Capability String
keyDown :: Capability String
keyDown = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kcud1"

keyLeft :: Capability String
keyLeft :: Capability String
keyLeft = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kcub1"

keyRight :: Capability String
keyRight :: Capability String
keyRight = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kcuf1"

-- | Look up the control sequence for a given function sequence.  For example, 
-- @functionKey 12@ retrieves the @kf12@ capability.
functionKey :: Int -> Capability String
functionKey :: Int -> Capability String
functionKey Int
n = forall f. OutputCap f => String -> Capability f
tiGetOutput1 (String
"kf" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
n)

keyBackspace :: Capability String
keyBackspace :: Capability String
keyBackspace = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kbs"

keyDeleteChar :: Capability String
keyDeleteChar :: Capability String
keyDeleteChar = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kdch1"

keyHome :: Capability String
keyHome :: Capability String
keyHome = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"khome"

keyEnd :: Capability String
keyEnd :: Capability String
keyEnd = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kend"

keyPageUp :: Capability String
keyPageUp :: Capability String
keyPageUp = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kpp"

keyPageDown :: Capability String
keyPageDown :: Capability String
keyPageDown = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"knp"

keyEnter :: Capability String
keyEnter :: Capability String
keyEnter = forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"kent"