                       cm
                       (group-by :y characters)))))
         (wait-for-key [this]
-          \a
-         #_ (.take key-queue))
+          (go-loop []
+            (let [c (async/<! key-chan)]
+              (if c
+                c
+                (recur)))))
         (set-cursor [this xy]
           (reset! cursor-xy xy))
         (refresh [this]
-          (buffers/clear-color-buffer gl 0.0 0.0 0.0 1.0)
-          (doseq [row (range rows)
-                  col (range columns)]
-            (let [c         (get-in @character-map [row col])
-                  x         (long (* col 12))
-                  y         (long (* (inc row) 16))
-                  highlight (= @cursor-xy [col row])]
-              (draw-character c x (- y 16)))))
+          (.requestAnimationFrame js/window (fn []
+            (buffers/clear-color-buffer gl 0.0 0.0 0.0 1.0)
+            (doseq [row (range rows)
+                    col (range columns)]
+              (let [c         (get-in @character-map [row col])
+                    x         (long (* col 12))
+                    y         (long (* (inc row) 16))
+                    highlight (= @cursor-xy [col row])]
+                (draw-character c x (- y 16)))))))
         (clear [this]
           (let [c (make-terminal-character \space default-fg-color default-bg-color #{})]
           (doseq [row (range rows)

  "Show a terminal and echo input."
  [& args]
  (let [terminal (make-terminal 80 20)]
    (animate (fn [frame]
      (rat/clear terminal)
      (rat/put-string terminal 5 5 "Hello world")
      (rat/refresh terminal)))
    #_(loop []
      (let [key-in (rat/wait-for-key terminal)]
        (rat/clear terminal)
        (rat/put-string terminal 5 5 "Hello world")
        (rat/put-string terminal 5 10 (str key-in))

                                     (.fillRect 0 0 screen-width screen-height))))))
                                   ;(doseq [row (range rows)]
                                   ;  (println (apply str (map #(get % :character) (get @character-map row)))))
          icon            nil #_(.getImage (java.awt.Toolkit/getDefaultToolkit) "images/icon.png")
          frame           nil #_(doto (JFrame. "Robinson")
                             (.. (getContentPane) (setLayout (BorderLayout.)))
