Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pprint #33

Merged
merged 6 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/babashka/nrepl/impl/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

(set! *warn-on-reflection* true)

(defn eval-msg [ctx o msg {:keys [debug] :as opts}]
(defn eval-msg [ctx o msg {:keys [debug pprint] :as opts}]
(try
(let [code-str (get msg :code)
reader (sci/reader code-str)
Expand Down Expand Up @@ -218,8 +218,9 @@
(utils/send os (utils/response-for msg {"status" #{"error" "unknown-op" "done"}}) opts)
(recur ctx is os id opts))))))

(defn listen [ctx ^ServerSocket listener {:keys [debug thread-bind] :as opts}]
(defn listen [ctx ^ServerSocket listener {:keys [debug thread-bind pprint] :as opts}]
(when debug (println "Listening"))
(when pprint (println "pretty-printing has been enabled"))
(let [client-socket (.accept listener)
in (.getInputStream client-socket)
in (PushbackInputStream. in)
Expand Down
11 changes: 9 additions & 2 deletions src/babashka/nrepl/impl/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@

(set! *warn-on-reflection* true)

;; TODO: should be based on this method here https://github.com/nrepl/nrepl/blob/0895caa7f0910c013014d554bbb262834a8408e4/src/clojure/nrepl/middleware/print.clj#L122
kolharsam marked this conversation as resolved.
Show resolved Hide resolved
(defn pretty-print [msg]
;; TODO: insert pretty printing logic here
)

(defn response-for [old-msg msg]
(let [session (get old-msg :session "none")
id (get old-msg :id "unknown")]
(assoc msg "session" session "id" id)))

(defn send [^OutputStream os msg {:keys [debug-send]}]
(defn send [^OutputStream os msg {:keys [debug-send pprint]}]
(when debug-send (prn "Sending" msg))
(write-bencode os msg)
(if pprint
(write-bencode os (pretty-print msg))
(write-bencode os msg))
(.flush os))

(defn send-exception [os msg ^Throwable ex {:keys [debug] :as opts}]
Expand Down
4 changes: 2 additions & 2 deletions src/babashka/nrepl/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{:author "Michiel Borkent"}
(:require [babashka.nrepl.impl.server :as server]
[clojure.string :as string]
[sci.core :as sci])
[sci.addons :as addons])
kolharsam marked this conversation as resolved.
Show resolved Hide resolved
(:import [java.net ServerSocket]))

(set! *warn-on-reflection* true)
Expand All @@ -19,7 +19,7 @@
{:host host
:port port}))

(defn start-server! [ctx & [{:keys [host port quiet]
(defn start-server! [ctx & [{:keys [host port quiet pprint]
:or {host "0.0.0.0"
port 1667}
:as opts}]]
Expand Down