{-# 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 = String -> Capability s
forall f. OutputCap f => String -> Capability f
tiGetOutput1 String
"smkx"

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

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

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

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

keyRight :: Capability String
keyRight :: Capability String
keyRight = String -> Capability String
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 = String -> Capability String
forall f. OutputCap f => String -> Capability f
tiGetOutput1 (String
"kf" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n)

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

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

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

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

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

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

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