我正在写一个简单的文本编辑器,所以我想要这样的东西
type Scancode = Int
data KeyState = Pressed | Released
newtype InStream = InStream [(Scancode, State)]
main = do
input <- getKeys
parse input
parse :: InStream -> IO ()
parse [] = return ()
parse (x : xs)
| x == (1, Released) = return ()
| otherwise = do
doSomething
parse xs
正如您可能猜到的,我希望getKeys
函数的行为类似于getContents
,具有连续的扫描码列表。
据我所知,SDL 甚至 GTK 都可以为我提供这样的功能,但是是否有更惯用的(对于 haskell 和函数式编程而言)以及更少的“开销”方式来做这样的事情?
PS 如果重要的话,我想在 Linux 下的控制台(tty)和 X11/Wayland 中使用我的“编辑器”。