        (on ::repl-pong #(deliver p true))
        (event ::repl-ping)
        (try 
-        (.get (future @p) 1000 TimeUnit/MILLISECONDS)
+        (.get (future @p) 300 TimeUnit/MILLISECONDS)
         (catch TimeoutException t 
           false))))
 

  (event ::repl-exit)

  (event ::repl-write :text "(println \"hello world\")")) 

;; GUI part


    (fn [pair] (-> pair set (filter string) count (mod 2) zero?))
    pairs)))

(do
 (defn repl []
   (let [group (sg-group)
         history (javax.swing.JEditorPane.)
         input (javax.swing.JEditorPane.)
         scroll (JScrollPane. history)

         println-history #(EDT (let [ doc (.getDocument history)
                                     length (.getLength doc)]
                                 (.insertString doc length % nil)))

         bb (CircularByteBuffer.)
         ps (java.io.PrintStream. (.getOutputStream bb) true)
         cr (ConsoleReader. (.getInputStream bb) (PrintWriter. (System/out)))
         ]

     (EDT (.setEditable input false)   
          (.setEditable history false)
          (.setVerticalScrollBarPolicy scroll (JScrollPane/VERTICAL_SCROLLBAR_ALWAYS))
          (.setHorizontalScrollBarPolicy scroll (JScrollPane/HORIZONTAL_SCROLLBAR_NEVER)))
    
     (doto group
       (add! (sg-component scroll 500 300))
       (add! (translate 0 305 (sg-component input 500 25))))

     (doto (.getKeymap input)
       (.addActionForKeyStroke
        (javax.swing.KeyStroke/getKeyStroke (java.awt.event.KeyEvent/VK_ENTER) 0)
        (proxy [javax.swing.AbstractAction] [] (actionPerformed [evt]  (let [text (.getText input)]
                                                                         (if (and (not (empty? text))
                                                                                  (balanced? text))
                                                                           (do (event ::repl-write :text text)
                                                                               (EDT
                                                                                (.setText input "")
                                                                                (.requestFocus input)))))))))

     
     
     (on ::repl-print #(println-history (:text %) ))
    
     (on ::repl-ready #((println-history "repl ready\r\n")
                        (event ::repl-write :text "(in-ns 'user)\r\n(use 'overtone.live)")
                        (EDT (.setEditable input true))))

     (on ::repl-exited #((println-history "repl exited\r\n")
                         (EDT (.setEditable input false))))
    
     (if (repl-thread-running?)
       (do (EDT (.setEditable input true))
           (println-history "repl thread allready running\r\n"))
       (start-repl-thread))
      
     group))


 (defn repl-panel []
   (let [panel (sg-panel)]

     (set-scene! panel (repl))

     panel))

 (sg-window (repl-panel))

 )

)
 (comment

   )

