 (ns sparkle.core
   (:require [clojure.core.async :refer [thread chan <!! >!! alt!! close!]]
-   [clojure.algo.generic.functor :refer [fmap]]
+            [clojure.algo.generic.functor :refer [fmap]]
             [com.stuartsierra.component :as component])
   (:gen-class))
 

            (if (= status :running)
              (alt!! command-chan ([command] (execute command state status)) 
                     :default (let [next-frame (render-step state)]
                                (to-displayer displayer next-frame)
                                [state :running]))
              (execute (<!! command-chan) state status))]
        (if loop-result

  "A protocol for things that are capable of displaying frames"
  (display [displayer frame] "Display a frame"))


;; The minimum time, in millis, between frames printed by ConsoleDisplayer
(def console-display-interval 500)

(defrecord ConsoleDisplayer [previous]
  component/Lifecycle
  (start [displayer]
    (assoc displayer
           :previous (atom {:frame nil
                            :time (- (now) console-display-interval)})))

  (stop [displayer]
    (dissoc displayer :previous))

  Displayer
  (display [{:keys [previous]} frame]
