skogsbaer / hscurses

ncurses binding for Haskell
http://hackage.haskell.org/package/hscurses
GNU Lesser General Public License v2.1
61 stars 21 forks source link

KeyLeft/Right/Up/Down interpreted as ESC on Mac OS X #4

Closed mcandre closed 13 years ago

mcandre commented 13 years ago

The docs show constructors for KeyLeft, KeyRight, KeyUp, and KeyDown, but when I press left, right, up, or down, they're all interpreted as Escape.

Example:

#!/usr/bin/env runhaskell

import UI.HSCurses.Curses

loopKey :: IO ()
loopKey = do
    k <- getCh
    putStrLn $ "Key: " ++ show k
    loopKey

main :: IO ()
main = do
    initCurses
    loopKey

(Press Up)

^[Key: KeyChar '\ESC'
                     [Key: KeyChar '['
                                      AKey: KeyChar 'A'

Specs:

hscurses 1.4.0.0 cabal 0.8.2 ghc 6.12.3 Mac OS X 10.6.6

mcandre commented 13 years ago

This issue raises several questions.

Why is there KeyLeft/Right/Up/Down and also cKEY_LEFT/RIGHT/UP/DOWN?

In GHCI, the c keys are distinct:

> cKEY_LEFT
260
> cKEY_RIGHT
261
> cKEY_LEFT == cKEY_RIGHT
False

So why does Haskell consider these patterns overlapping?

case k of
    cKEY_LEFT -> putStrLn $ "Pressed Left"
    cKEY_RIGHT -> putStrLn $ "Pressed Right"
    cKEY_UP -> putStrLn $ "Pressed Up"
    cKEY_DOWN -> putStrLn $ "Pressed Down"
    otherwise -> putStrLn $ "Pressed something else"

Why does this always evaluate to "Pressed something else"?

case k of
    cKEY_UP -> putStrLn $ "Pressed Up"
    otherwise -> putStrLn $ "Pressed something else"

And why does that always evaluate to "Pressed Up", no matter which arrow key is pressed?

skogsbaer commented 13 years ago

You need to add

keypad stdScr True

after initCurses and before loopKey