1

我正在写一个简单的文本编辑器,所以我想要这样的东西

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 中使用我的“编辑器”。

4

1 回答 1

1

如果您真的想要简单,请查看以下答案:

您可能必须首先将您的 tty 置于原始模式才能使其工作。第二个问题要求 Windows 解决方案,但同样的想法也适用于 Linux。

于 2015-08-26T22:22:53.573 回答