在Clojure中读取未缓冲的键盘输入 [英] Reading unbuffered keyboard input in Clojure
问题描述
如何在Clojure中从终端(不是Swing)中读取单个键击?
How does one read a single keystroke from the terminal (not Swing) in Clojure?
我已经尝试了一些操作,包括各种各样的 版本的JLine库,但没有得到它的工作(见
I have tried a few things including various versions of the JLine library, but have not gotten it working (see example below).
我会高兴地接受一个工作,只有Unix(Mac,Linux,...)的例子。理想情况下,我想知道如何关闭stdin和stdout的缓冲。
I will happily accept a working, Unix-only (Mac, Linux, ...) example. Ideally I'd like to know how to switch buffering off for both stdin and stdout.
这里有一些关闭:
;; project.clj dependencies:
;; [[org.clojure/clojure "1.4.0"]
;; [jline/jline "2.8"]])
(ns slosh.core
(:import [jline.console ConsoleReader])
(:gen-class))
(defn -main []
(println "start")
(let [cr (ConsoleReader.)]
(.readCharacter cr)
(println "done")))
这将打印start,但不会响应任何输入, C。
This prints "start" but does not respond to any input except control-C.
推荐答案
我不知道你是如何运行这个,但如果你使用运行
,你会遇到问题。尝试使用 lein trampoline run
。
I'm not sure how you are running this, but if you are using lein run
, you will run into problems. Try using lein trampoline run
.
我会链接单个字符控制台输入在java / clojure ,但我似乎没有足够的互联网点来做。
I would link Single character console input in java/clojure but I don't seem to have enough Internet Points to do that.
这篇关于在Clojure中读取未缓冲的键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!