Skip to content

Commit 27625d3

Browse files
committed
Allow filtering for pprint viewer
- elide binary values by default in pprint viewer
1 parent 97a4d18 commit 27625d3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/portal/ui/rpc.cljs

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
(-pr-writer [this writer _opts]
2222
(-write writer (str this "N"))))
2323

24-
(when (exists? js/Uint8Array)
25-
(extend-type js/Uint8Array
26-
IPrintWithWriter
27-
(-pr-writer [this writer _opts]
28-
(-write writer "#portal/bin \"")
29-
(-write writer (cson/base64-encode this))
30-
(-write writer "\""))))
31-
3224
(extend-type array
3325
IHash
3426
(-hash [this]

src/portal/ui/viewer/pprint.cljs

+26-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(:require [clojure.pprint :as pp]
33
[clojure.string :as str]
44
[portal.runtime.cson :as cson]
5+
[portal.ui.filter :as f]
6+
[portal.ui.inspector :as ins]
57
[portal.ui.viewer.code :as code]))
68

79
(defn- queue? [obj]
@@ -13,6 +15,7 @@
1315
(defn- type-dispatcher [obj]
1416
(cond
1517
(cson/tagged-value? obj) :tagged
18+
(ins/bin? obj) :bin
1619

1720
(queue? obj) :queue
1821
(deref? obj) :deref
@@ -26,6 +29,24 @@
2629

2730
(defmulti pprint-dispatch type-dispatcher)
2831

32+
(def ^:dynamic *elide-binary* false)
33+
34+
(when (exists? js/Uint8Array)
35+
(extend-type js/Uint8Array
36+
IPrintWithWriter
37+
(-pr-writer [^js/Uint8Array this writer _opts]
38+
(-write writer "#object[Uint8Array ")
39+
(-write writer (.-length this))
40+
(-write writer "]"))))
41+
42+
(defmethod pprint-dispatch :bin [value]
43+
(if *elide-binary*
44+
(-write *out* (pr-str value))
45+
(do
46+
(-write *out* "#portal/bin \"")
47+
(-write *out* (cson/base64-encode value))
48+
(-write *out* "\""))))
49+
2950
(defmethod pprint-dispatch :tagged [value] (-write *out* (pr-str value)))
3051
(defmethod pprint-dispatch :list [value] (#'pp/pprint-list value))
3152
(defmethod pprint-dispatch :vector [value] (#'pp/pprint-vector value))
@@ -38,12 +59,14 @@
3859
(pp/set-pprint-dispatch pprint-dispatch)
3960

4061
(defn pprint-data [value]
41-
(let [options (:portal.viewer/pprint (meta value))]
62+
(let [options (:portal.viewer/pprint (meta value))
63+
search-text (ins/use-search-text)]
4264
(binding [*print-meta* (:print-meta options (coll? value))
4365
*print-length* (:print-length options 25)
44-
*print-level* (:print-level options 5)]
66+
*print-level* (:print-level options 5)
67+
*elide-binary* true]
4568
[code/highlight-clj
46-
(str/trim (with-out-str (pp/pprint value)))])))
69+
(str/trim (with-out-str (pp/pprint (f/filter-value value search-text))))])))
4770

4871
(def viewer
4972
{:predicate (constantly true)

0 commit comments

Comments
 (0)