|
2 | 2 | (:require [clojure.pprint :as pp]
|
3 | 3 | [clojure.string :as str]
|
4 | 4 | [portal.runtime.cson :as cson]
|
| 5 | + [portal.ui.filter :as f] |
| 6 | + [portal.ui.inspector :as ins] |
5 | 7 | [portal.ui.viewer.code :as code]))
|
6 | 8 |
|
7 | 9 | (defn- queue? [obj]
|
|
13 | 15 | (defn- type-dispatcher [obj]
|
14 | 16 | (cond
|
15 | 17 | (cson/tagged-value? obj) :tagged
|
| 18 | + (ins/bin? obj) :bin |
16 | 19 |
|
17 | 20 | (queue? obj) :queue
|
18 | 21 | (deref? obj) :deref
|
|
26 | 29 |
|
27 | 30 | (defmulti pprint-dispatch type-dispatcher)
|
28 | 31 |
|
| 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 | + |
29 | 50 | (defmethod pprint-dispatch :tagged [value] (-write *out* (pr-str value)))
|
30 | 51 | (defmethod pprint-dispatch :list [value] (#'pp/pprint-list value))
|
31 | 52 | (defmethod pprint-dispatch :vector [value] (#'pp/pprint-vector value))
|
|
38 | 59 | (pp/set-pprint-dispatch pprint-dispatch)
|
39 | 60 |
|
40 | 61 | (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)] |
42 | 64 | (binding [*print-meta* (:print-meta options (coll? value))
|
43 | 65 | *print-length* (:print-length options 25)
|
44 |
| - *print-level* (:print-level options 5)] |
| 66 | + *print-level* (:print-level options 5) |
| 67 | + *elide-binary* true] |
45 | 68 | [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))))]))) |
47 | 70 |
|
48 | 71 | (def viewer
|
49 | 72 | {:predicate (constantly true)
|
|
0 commit comments